활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
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();
}
}
}
조회 수
답글
좋아요 수
below is working for me
import java.io.IOException;
import java.rmi.ServerException;
import javax.servlet.Servlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.HttpConstants;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Component;
@Component(service = Servlet.class, property = { Constants.SERVICE_DESCRIPTION + "=Simple Demo Redirect Servlet",
"sling.servlet.methods=" + HttpConstants.METHOD_POST, "sling.servlet.paths=" + "/bin/test/redirect" })
public class SimpleRedirectServlet extends SlingSafeMethodsServlet {
private static final long serialVersionUID = 2598426539166789516L;
@Override
protected void doGet(final SlingHttpServletRequest req, final SlingHttpServletResponse resp)
throws ServerException, IOException {
try {
resp.sendRedirect("/content/we-retail/us/en/user.html");
} catch (Exception e) {
e.printStackTrace();
}
}
}
조회 수
답글
좋아요 수
Hi Arun,
Thanks for your reply.
Does your page load with user.html page and browser url also have /content/we-retail/us/en/user.html in url locator.
I am using AEM 6.3.3 version.
Thanks,
Sai
조회 수
답글
좋아요 수
조회 수
답글
좋아요 수
Are you calling this servlet from javascript ajax ?
조회 수
답글
좋아요 수
Hi Sai,
Could you please let us know how you are trying to access?
As arun suggested it should work whether you are calling through script or browser once your servlet is called it should redirect to respective path.
조회 수
답글
좋아요 수
Are you trying to achieve this from a button in Granite UI dialog?
조회 수
답글
좋아요 수
조회 수
Like
답글
조회 수
Likes
답글
조회 수
Likes
답글
조회 수
Likes
답글