3

I have a portlet where the doView method calls the display.jsp page with the following instruction :

getPortletContext().getRequestDispatcher("/views/display.jsp").dispatcher.include(request, response);

In the display.jsp, I want to do a redirection to an external website :

<%
response.sendRedirect("http://www.google.fr");
%>

Why is it not working at all ? (I put a <div>foobar<div> in the JSP to see if that works and it does) Is there another solution to make a redirection to an external URL ?

(The idea is to "stay" in the portlet/portal where the user can see the "targetted" website)

Regards.

4

1 回答 1

1

如果您查看Portlet 2.0 规范的第 141 页,它提到 HttpServletRespone#sendRedirect() 在呈现阶段是一个 NO-OP。

所以这就是你看不到这个工作的原因。根据语义,响应对象是一个 HttpServletResponse,它对应于整个页面的响应,而不仅仅是该 JSP 所属的 portlet。由于页面现在是多个 portlet 的组合,并且每个 portlet 都有自己的生命周期,因此您应该使用 renderResponse、actionResponse 对象之一,并避免使用 servlet 对象。

不过,我还没有找到解决您原来问题的方法。

于 2014-02-16T05:33:07.763 回答