Dispatch request to a page component from Servlet | Community
Skip to main content
viren_pushpanay
October 16, 2015
Solved

Dispatch request to a page component from Servlet

  • October 16, 2015
  • 3 replies
  • 2359 views

Hi,

How to I dispatch a request to a page component (JSP)? I get the following error javax.jcr.nodetype.ConstraintViolationException: no matching property definition found for {}country. I don't want the country value to be persisted.

The code I used to dispatch from the servlet is:

RequestDispatcher dispatcher = request.getRequestDispatcher("/content/mycompany/cars/audi/a4.html");
dispatcher.forward(request, response);

Thanks you.

Cheers,

Viren.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by viren_pushpanay

What I did was use the SlingHttpServletRequestWrapper class to convert the form method to GET from POST and then dispatch it. The below code worked for me.

org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper req = new org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper(request) { public String getMethod() { return "GET"; } }; String path = "/content/mycompany/shippingDetails.html"; javax.servlet.RequestDispatcher dispatcher = request.getRequestDispatcher(path); dispatcher.include(req, response);

3 replies

viren_pushpanay
viren_pushpanayAuthorAccepted solution
October 16, 2015

What I did was use the SlingHttpServletRequestWrapper class to convert the form method to GET from POST and then dispatch it. The below code worked for me.

org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper req = new org.apache.sling.api.wrappers.SlingHttpServletRequestWrapper(request) { public String getMethod() { return "GET"; } }; String path = "/content/mycompany/shippingDetails.html"; javax.servlet.RequestDispatcher dispatcher = request.getRequestDispatcher(path); dispatcher.include(req, response);
Sham_HC
October 16, 2015

It seems you are posting to a page resource url directly. If you are not persisting why are you using post request.

smacdonald2008
October 16, 2015

According to this illustration located here http://dev.day.com/docs/en/cq/current/deploying/dispatcher.html:

[img]dd.png[/img]

Dispatcher goes through a flowchart to determine if the page is cached or not. Have you ensured that the Dispatcher is properly configured. Please read this AEM Topic:

http://dev.day.com/docs/en/cq/current/deploying/dispatcher/disp_config.html