[英]Unable to redirect to another page in AEM using request dispatcher in sling servlet via POST
I have a scenario where from one page in AEM, I need to call another AEM page in the same application and I need to pass some hidden parameters. 我有一个场景,在AEM的一个页面中,我需要在同一应用程序中调用另一个AEM页面,并且需要传递一些隐藏参数。 I choose to do it via POST and below are the steps which I followed: From page "A", I did a form submission via POST to the sling servlet and passed some parameters.
我选择通过POST进行操作,以下是我遵循的步骤:从页面“ A”,我通过POST向吊索servlet提交了表单提交并传递了一些参数。 2. In the servlet, using request dispatcher I redirected the same request and response to a different page in doPost method using the following code snippet:
2.在servlet中,使用请求分派器,使用以下代码片段将相同的请求和响应重定向到doPost方法中的不同页面:
request.getRequestDispatcher("/content/company/en/apps/welcomepage.html").forward(request, response);
When I run the code, I am able to call the servlet through form submission but I am not able to redirect to a new page. 运行代码时,我可以通过表单提交来调用servlet,但是不能重定向到新页面。 I see the below error in logs:
我在日志中看到以下错误:
18.10.2017 14:41:00.802 ERROR [127.0.0.1 [1508352060795] POST /bin/rap/welcomepage HTTP/1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation Exception during response processing. 18.10.2017 14:41:00.802 错误 [127.0.0.1 [1508352060795] POST / bin / rap / welcomepage HTTP / 1.1] org.apache.sling.servlets.post.impl.operations.ModifyOperation响应处理期间的异常。 javax.jcr.nodetype.ConstraintViolationException: No matching property definition: appointmentTypeId = platform001d at org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522) at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1375) at org.apache.jackrabbit.oak.jcr.session.NodeImpl$35.perform(NodeImpl.java:1363) at org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate.perform(SessionDelegate.java:208) at org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112) at org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty(NodeImpl.java:1363)
javax.jcr.nodetype.ConstraintViolationException:没有匹配的属性定义:org.apache.jackrabbit.oak.jcr处的约会类型=平台001d在org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate.setProperty(NodeDelegate.java:522)处。在org.apache.jackrabbit.oak.jcr.session的session.NodeImpl $ 35.perform(NodeImpl.java:1375)在org.apache.jackrabbit.oak.jcr.delegate的session.NodeImpl $ 35.perform(NodeImpl.java:1363)。 org.apache.jackrabbit.oak.jcr.session.ItemImpl.perform(ItemImpl.java:112)的SessionDelegate.perform(SessionDelegate.java:208)org.apache.jackrabbit.oak.jcr.session.NodeImpl.internalSetProperty( NodeImpl.java:1363)
If I try the same code in doGet method it works fine. 如果我在doGet方法中尝试相同的代码,则效果很好。 Also if I use response.sendRedirect("/content/company/en/apps/welcomepage.html") it works fine too.
另外,如果我使用response.sendRedirect(“ / content / company / en / apps / welcomepage.html”),它也可以正常工作。 But the problem with this is it initiates it as a new request to the page and it looses all the parameters which I get from the form submission.
但是,这样做的问题是它将它作为对页面的新请求启动,并失去了我从表单提交中获得的所有参数。 Could someone please let me know like how can I redirect a request to a page in AEM via POST since I need to pass some hidden parameters whic should not be visible in the url ?
有人可以让我知道,例如如何通过POST将请求重定向到AEM中的页面,因为我需要传递一些隐藏参数,而url中应该不可见?
Here is the way I understand your question 这是我理解您问题的方式
POST
request and calls: request.getRequestDispatcher("/content/company/en/apps/welcomepage.html").forward(request, response);
POST
请求并调用: request.getRequestDispatcher("/content/company/en/apps/welcomepage.html").forward(request, response);
Why do you get this exception? 为什么会出现此异常?
Since you are using forward
the POST
request is forwarded to /content/company/en/apps/welcomepage.html
that node is most likely of type cq:Page
, which has constraints on which properties can be added. 由于您正在使用
forward
因此POST
请求将转发到/content/company/en/apps/welcomepage.html
,该节点最有可能是cq:Page
类型,该类型对可以添加属性有限制。 Think of it as a simple post request trying to store parameters on the cq:Page
node. 可以将其视为一个简单的发布请求,尝试将参数存储在
cq:Page
节点上。
What can you do? 你能做什么?
Since I don't understand your use-case and particularly why you need to preserve the submit params, I cannot recommend a specific solution. 由于我不了解您的用例,尤其是为什么您需要保留提交参数,因此我不建议您使用特定的解决方案。 However, since you don't want the parameters in the URL, here is a potential solution you can try:
但是,由于您不需要URL中的参数,因此可以尝试以下解决方案:
response.sendRedirect("/content/company/en/apps/welcomepage.html")
response.sendRedirect("/content/company/en/apps/welcomepage.html")
/content/company/en/apps/welcomepage.html
, you can get the request cookies and process them however you like. /content/company/en/apps/welcomepage.html
任何组件上,您都可以获取请求cookie并根据需要进行处理。 same way you wanted to process those hidden params. Now the flow becomes: 现在流程变为:
POST
request, adds your special params to cookies on the response, then calls response.sendRedirect("/content/company/en/apps/welcomepage.html")
POST
请求,将特殊参数添加到响应的Cookie中,然后调用response.sendRedirect("/content/company/en/apps/welcomepage.html")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.