Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

How to render HTMl of page using Externalurl in AEM?

Avatar

Level 4

Can anyone help me, How I can render the html of page by using externalUrl using Servlet

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @vinuu123 ,

You can follow below steps to render externalUrl using Servlets.

  1. Create a custom Servlet in AEM that will handle the request to fetch and render the external HTML content.
  2. In the Servlet, use Java libraries or frameworks (e.g., Apache HttpClient) to fetch the HTML content from the external URL.
  3. Once you've fetched the HTML content, you can process it and render it as needed. You can use methods like response.getWriter().write(htmlContent) to write the fetched HTML to the response.
  4. In JavaScript write a ajax call to fetch the response.
  5. Append the external html using JavaScript code on the basis of ID,<div id = "external-form">

Thanks & Regards

Shiv

Shiv Prakash

View solution in original post

2 Replies

Avatar

Employee

Hi @vinuu123 

You can make an httpclient call with getmethod by setting the URL like "http://host:port/pagepath.html".
Make sure you add the content type to the header before executing. For any manipulation in Html you can use Jsoup.

Avatar

Correct answer by
Community Advisor

Hi @vinuu123 ,

You can follow below steps to render externalUrl using Servlets.

  1. Create a custom Servlet in AEM that will handle the request to fetch and render the external HTML content.
  2. In the Servlet, use Java libraries or frameworks (e.g., Apache HttpClient) to fetch the HTML content from the external URL.
  3. Once you've fetched the HTML content, you can process it and render it as needed. You can use methods like response.getWriter().write(htmlContent) to write the fetched HTML to the response.
  4. In JavaScript write a ajax call to fetch the response.
  5. Append the external html using JavaScript code on the basis of ID,<div id = "external-form">

Thanks & Regards

Shiv

Shiv Prakash