URL does not change with RequestDispatcher forward
There are several posts on the same topic, but they do not have a clear solution and code-snippets.
When i do a Forward using RequestDispatcher.. the result page loads but the URL does not change.
The URL where we start and Submit data to the PostServlet: http://localhost:4502/content/ttii/en/postformtest.html
Final result URL should be: http://localhost:4502/content/ttii/en/postformtestresult.html
But is: http://localhost:4502/services/processFormData
Would appreciate help!
HTML Form
<form name="userRegistrationForm" method="post" action="/services/processFormData"> <input type="submit" title="Submit" class="btn submit btn-success" value="Submit" tabindex="25" name="bttnAction"> </form>
My Servlet class..
@SlingServlet( label = "TTI - TTICommon POST Servlet", metatype = true, methods = { "POST" }, name="com.tti.tticommons.service.servlets.TTIPostServlet", paths = { "/services/processFormData" } ) public class TTIPostServlet extends SlingAllMethodsServlet{ @Override protected void doPost(SlingHttpServletRequest request,SlingHttpServletResponse response) throws ServletException,IOException { final SlingHttpServletRequest syntheticRequest = new SyntheticSlingHttpServletGetRequest(request); final RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSelectors(""); options.setForceResourceType("cq/Page"); request.getRequestDispatcher("/content/ttii/en/postformtestresult.html", options).forward(syntheticRequest, response); } }
the Wrapper Servlet:
public class SyntheticSlingHttpServletGetRequest extends SlingHttpServletRequestWrapper { private static final String METHOD_GET = "GET"; public SyntheticSlingHttpServletGetRequest(final SlingHttpServletRequest request) { super(request); } @Override public String getMethod() { return METHOD_GET; } }