Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.
Nível 1
Nível 2
Faça login na Comunidade
Faça logon para exibir todas as medalhas
Esta conversa foi bloqueada devido à inatividade. Crie uma nova publicação.
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; } }
Solucionado! Ir para a Solução.
Visualizações
respostas
Total de curtidas
This is the expected behavior of RequestDispatcher.forward(). You can't change the URL and keep the request context (attributes).
Visualizações
respostas
Total de curtidas
Why don't you use response.sendRedirect() method instead of using the forward method of request dispatcher ?
Visualizações
respostas
Total de curtidas
Thanks for your note.
response.sendRedirect() will solve the redirection issue and the url will change. But i will loose the data that came along with the POST. This data is in "syntheticRequest" above.
Visualizações
respostas
Total de curtidas
Are you following an AEM doc or example from community? Did you see this thread that Sham answered:
Visualizações
respostas
Total de curtidas
I'm using a custom code.
But i'm stuck here.. If i use..
A) include or forward, then i can retrieve the values set as "request.setAttribute" in the result page. The page is forwarded and displays the result page, but the URL does not change. Shows as http://localhost:4502/services/processFormData instead it should be http://localhost:4502/content/ttii/en/postformtestresult.html
RequestDispatcher dispatcher = request.getRequestDispatcher(responseHtml); dispatcher.include(syntheticRequest, response); or dispatcher.forward(syntheticRequest, response); [Where 'syntheticRequest' is SlingHttpServletRequestWrapper]
B) If i use, 'sendRedirect', the URL changes to the result page, but i'm loosing the attributes set to the request.
final SlingHttpServletRequest syntheticRequest = new SyntheticSlingHttpServletGetRequest(request); response.sendRedirect(responseHtml); [Where 'syntheticRequest' is SlingHttpServletRequestWrapper]
Visualizações
respostas
Total de curtidas
This is the expected behavior of RequestDispatcher.forward(). You can't change the URL and keep the request context (attributes).
Visualizações
respostas
Total de curtidas
Thanks.
1. I'm curious to know how does the OutOfTheBox AEM Form Components handle such situation?
2. There are some blogs/forums that referred me to use a Filter. Does this have any relevance here?
com.day.cq.wcm.foundation.forms.impl.FormsHandlingServlet [ http://docs.adobe.com/docs/v5_1/cq-wcm-javadoc/com/day/cq/wcm/foundation/forms/impl/FormsHandlingSer... ]
Visualizações
respostas
Total de curtidas
Visualizações
Curtida
respostas
Visualizações
Curtida
respostas