Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Validate 1
Level 1
sunitac93243435
Level 1

Likes

2 likes

Total Posts

20 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 1
Level 1
sunitac93243435
Level 1

Likes

2 likes

Total Posts

20 posts

Correct Reply

1 solution
Top badges earned
Validate 1
Boost 1
Affirm 1
View profile
sunitac93243435
Level 1

18-03-2020

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.

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

590 posts

Correct Reply

231 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile

Avatar
Establish
MVP
BrianKasingli
MVP

Likes

613 likes

Total Posts

590 posts

Correct Reply

231 solutions
Top badges earned
Establish
Ignite 1
Give Back 5
Give Back 3
Give Back 10
View profile
BrianKasingli
MVP

18-03-2020

@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.

Answers (0)