On 11/23/05, Michael Jouravlev <[EMAIL PROTECTED]> wrote:
>
> I know that this is not a proper list, but considering that original
> author of Tomcat spends a lot of time here I thought it was worth a
> shot ;) Also, I didn't want to go through hassle of
> subscribing/unsubscribing to Tomcat mailing list, I hoped I would get
> help in my home list ;)


:-)


As I said, I use Tomcat 4 (4.0.31 to be precise), which is compliant
> with SRV2.3 /JSP1.2 spec. Therefore I am allowed to use <jsp:include
> flush="false"/> or without flush attribute at all; included resource
> should be buffered. My problem is that I cannot do a redirect from
> included page.
>
> This works:
> -----------
>
> main.jsp --- (begin) ---
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <html>
> <body>
> <%
>   if ("POST".equalsIgnoreCase( request.getMethod())) {
>     String redirectURL = request.getRequestURL().toString();
>     response.sendRedirect(redirectURL);
>   }
> %>
> <form method="POST">
>   <input type="submit" name="submitkey" value="Submit"/>
> </form>
> </body>
> </html>
> main.jsp --- (end) ---
>
> When I load the main.jsp page, it shows the form. When I submit the
> form, it processes POST and redirects back to the same page. Exactly
> what I need.
>
> This does not work:
> -------------------
>
> main2.jsp --- (begin) ---
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <html>
> <body>
>   <jsp:include page="inc2.jsp"/>
> </body>
> </html>
> main2.jsp --- (end) ---
>
> inc2.jsp --- (begin) ---
> <%@ page contentType="text/html;charset=UTF-8" language="java" %>
> <%
>   if ("POST".equalsIgnoreCase(request.getMethod())) {
>     String redirectURL = request.getRequestURL().toString();
>     response.sendRedirect(redirectURL);
>   }
> %>
> <form method="POST">
>   <input type="submit" name="submitkey" value="Submit"/>
> </form>
> inc2.jsp --- (end) ---
>
> When I load main2.jsp, it shows the form. When I submit it, scriptlet
> calls sendRedirect, but browser does not redirect. LiveHTTPHeaders
> shows that instead of 302 browser receives a regular 200. On the other
> hand, when I was sending redirect, response was not committed yet, and
> no exceptions were thrown.
>
> I tried to replace
>     response.sendRedirect (redirectURL);
> with
>     response.reset();
>     response.sendRedirect(redirectURL);
>     response.flushBuffer();
> but this did not work either.


Eewwwww ... scriptlets!  :-)

Does anyone have a clue?


You can't change HTTP headers (which is what is required to do a redirect)
from inside a RequestDispatcher.include() -- and that's what <jsp:include>
does under the covers.  It would work with a static include (<%@ include
file="..." %>) though.

Of course, redirect-after-post also seems like something you'd want to
implement in a controller somehow, not in every view.

Michael.


Craig

Reply via email to