Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

How to Get Post Servlet value in my HTML page in AEM 6.5 ?

Avatar

Level 2

Dear All,

 

I have one requirement for my password reset page.

 

1) When User click on password reset URL (For example http://localhost:4502/content/sunita/passwordReset.html?sunitauniqueid=12344fhjiikj3455) , then I need to call this sunitauniqueid param in my servlet code and can get the requestedUserID by using some below code.

 

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.osgi.service.component.annotations.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@component(immediate = true,
service = Servlet.class,
property = {"sling.servlet.paths=/bin/sunita/rest/password-reset",
"sling.servlet.methods=POST"})
public class SunitaPwdResetGetServlet extends SlingAllMethodsServlet {

private static final long serialVersionUID = 1L;

private static final Logger log = LoggerFactory.getLogger(SunitaPwdResetGetServlet.class);

@Override
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException {
PrintWriter respWriter = null;
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build())
{
respWriter = response.getWriter();
String requestedUserID = request.getParameter("sunitauniqueid");
log.info("userName ======= "+ requestedUserID);
}
catch (IOException e) {
log.error("Error in Password Reset", e);
} finally {
if (respWriter != null) {
response.setContentType("application/json");
respWriter.print("{}");
respWriter.flush();
respWriter.close();
}
}
}
}

 

2) Now , I want to display this requestedUserID from my above servlet code to my Frontend ,like below.

 
 

password-reset.PNG

 

 

 

My HTL code is below..I have hard coded here the requestedUserID value.How can I get my requestedUserID in my frontEnd ?

 

<div class="requestedUserIDContainer">
<h1>requestedUserID = *****1234</h1>
</div>

 

Please help me on this

Thanks In advance.

 

 
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@sunitac93243435,

Here's what you can try:

  1. Visit: http://localhost:4502/content/sunita/passwordReset.html?sunitauniqueid=12344fhjiikj3455
  2. The passWordReset.html page will have Javascript that will make a POST request call that returns a JSON response object.
  3. Javascript will use the JSON response object to dynamically modify HTML elements on the page; interpolate JSON values to the page. 

I hope this helps, 

Brian.

View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

@sunitac93243435,

Here's what you can try:

  1. Visit: http://localhost:4502/content/sunita/passwordReset.html?sunitauniqueid=12344fhjiikj3455
  2. The passWordReset.html page will have Javascript that will make a POST request call that returns a JSON response object.
  3. Javascript will use the JSON response object to dynamically modify HTML elements on the page; interpolate JSON values to the page. 

I hope this helps, 

Brian.

Avatar

Level 2

Can you please give me the example for below 2 points.

 

  1. The passWordReset.html page will have Javascript that will make a POST request call that returns a JSON response object.
  2. Javascript will use the JSON response object to dynamically modify HTML elements on the page; interpolate JSON values to the page.