How to render HTMl of page using Externalurl in AEM? | Community
Skip to main content
Level 3
August 29, 2023
Solved

How to render HTMl of page using Externalurl in AEM?

  • August 29, 2023
  • 2 replies
  • 803 views

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

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Shiv_Prakash_Patel

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

2 replies

varun249715
Adobe Employee
Adobe Employee
August 29, 2023

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.

Shiv_Prakash_Patel
Community Advisor
Shiv_Prakash_PatelCommunity AdvisorAccepted solution
Community Advisor
August 29, 2023

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