Search code examples
jspportletliferay

Is redirection to portlets possible ? [ Portlets + JSP]


I invoke a jsp page by clicking a link in my portlet. Within the jsp, after some computations, I am trying to send a redirect request back to the portlet via the response.sendRedirect() method. But instead of going over to the redirected page, the portlet simply publishes code that should not be seen.

What am I doing wrong ??

..... some declarations and methods for computing stuff.... .
<%
String redirect = generateRedirect(request, name);
response.sendRedirect(redirect);
%>

<html>
    <head>
        <title>Testing Portlet redirect</title>
    </head>
    <body>

        You should never see this page.

    </body>
</html>

Solution

  • redirection typically is done through the 302 response code, sent in a HTTP header. When you're inside a portlet, you can't just send response codes out - in fact, the response headers might even be flushed out already when your jsp is rendered. Therefor there's no use in using redirect in portlet environments. You should rather use conditional processing (if/else) in your jsp or logic within your portlet to dispatch to different jsps in the first place.