How to make the ResourceResponse to forward the request to error page in liferay portlet

廉价感情. 提交于 2019-12-01 19:50:26

Im not sure but my guess would be that you didnt set any render parameter when redirecting to your error page.

Try this and see if it helps in any way (you can place it instead of the line with dispatcher):

response.setRenderParameter("jspPage", "/WEB-INF/views/html/jsp/error.jsp");

I am using this kind of redirects with actionResponse but it should work with resourceResponse as well...

EDIT: resource response does not contain setRenderParameter method, but zou can try to use the following approach:

create renderURL using response.createRenderURL(). If a request is triggered using this URL, it will result in render request/response (or action request which can access that method).

The problem is, that you are trying to redirect to another page during resource phase of the portlet (render phase in not called during this phase).

I'm not 100% sure this would work in the resourcePhase, but you could try

com.liferay.portal.kernel.servlet.SessionErrors.add(request, "your Error message here");
sarM

I had a similar issue. This works -

PortletURL renderUrl = resourceResponse.createRenderURL();  
renderUrl.setParameter("renderException", ex.toString());   
resourceResponse.addProperty("Location", renderUrl.toString());

Maybe it is not forwarding because the response has already been committed because you have written something in it. That could explain why include works and forward doesn't.

You can check whether the response has already been committed using resourceResponse.isCommitted() in your catch block.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!