redirect to a content page in aem servlet
I was trying to redirect to another content page in aem servlet. It is returning 200 OK response in network tab but NEVER goes to the specified redirect page.
Is this how AEM works, if so, Do I need to make any changes in configurations or any other code changes to get this redirect work as in a regular servlet application.
I appreciate any help.
I tried both redirect and forward as you can see in below code. In case of forward I am getting 500 error in network tab.
@Component(immediate = true, service = Servlet.class, property = { "sling.servlet.paths=/bin/test/redirect"})
public class TestRedirectServlet extends SlingAllMethodsServlet{
private static final long serialVersionUID = 3591693830449607948L;
@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) {
PrintWriter writer = null;
try {
writer = response.getWriter();
// final RequestDispatcherOptions options = new RequestDispatcherOptions();
// final SlingHttpServletRequest syntheticRequest = new SyntheticSlingHttpServletGetRequest(request);
// request.getRequestDispatcher("/content/best-western/en_US.html", options).forward(syntheticRequest, response);
// return;
response.sendRedirect("/content/test-site/sample.html");
}
} catch(Exception e){
}
finally {
if (writer != null) {
writer.print("done");
writer.flush();
writer.close();
}
}
}