You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Michael Jouravlev <jm...@gmail.com> on 2005/11/23 19:07:11 UTC

[OT] redirect does not work from included page in Tomcat 4

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.

Does anyone have a clue?

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] redirect does not work from included page in Tomcat 4

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/23/05, Dave Newton <ne...@pingsite.com> wrote:
> My understanding was that once content was sent to the browser you could
> no longer do a redirect, so I'd think that once you started dealing with
> the include file it'd be too late.

That was true for JSP 1.1. Starting from JSP 1.2 you can use
flush="false" attribute to buffer included resources. Funny thing it
works in Struts app where I have included action and redirect from it.
This time I tried to do similar thing in JSP and cannot make it work.
Oh, Tomcat is 4.1.31, not 4.0.31, but this should not matter.

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] redirect does not work from included page in Tomcat 4

Posted by Dave Newton <ne...@pingsite.com>.
Michael Jouravlev wrote:

>Does anyone have a clue?
>  
>
My understanding was that once content was sent to the browser you could 
no longer do a redirect, so I'd think that once you started dealing with 
the include file it'd be too late.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] redirect does not work from included page in Tomcat 4

Posted by Michael Jouravlev <jm...@gmail.com>.
On 11/23/05, Craig McClanahan <cr...@apache.org> wrote:
> 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.

Then what is flush="false" good for? I thought that the whole point is
to wait sending response to client, allowing included resource to do
its thing. Also, what about this sequence:
   response.reset();
   response.sendRedirect(redirectURL);
   response.flushBuffer();
Should not it clean the [yet uncommitted] response, and set a proper
header in it?

> It would work with a static include (<%@ include> file="..." %>) though.

Hmm... <jsp:include> definetely works in this setup:

struts-config.xml:
-----------------
<action path = "/main" forward = "/mainpage.jsp"/>

mainpage.jsp:
------------
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
  ...
  <jsp:include page="/login.do"/>
  ...

struts-config.xml again:
-----------------------
<action path = "/login"
  ...
  <forward name = "RELOAD" path = "/main.do" redirect = "true"/>
  <forward name = "VIEW" path = "/login-fragment.jsp"/>
</action>

You can see, that I dynamically include login.do action, it renders
its view. Then I submit input directly to that action and redirect to
main page... Oh, I see the difference now! In the working example I
submit directly to included resource, while in non-working example I
submit to the enclosing parent page. Duh! So the POST in the working
example does not involve calling <jsp:include>.

Still, I cannot get why it should not work with include, I thought
that the whole point of flush="false" is to make it happen. If it is
not for that, that what for?

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

Yes, you are probably right. I am just trying things ;-)

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] redirect does not work from included page in Tomcat 4

Posted by Craig McClanahan <cr...@apache.org>.
On 11/23/05, Michael Jouravlev <jm...@gmail.com> 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

Breaking out of an HTTPS session

Posted by Frank Burns <fr...@the-hub.demon.co.uk>.
I have created a Web application using Struts 1.2 with Tomcat 5.5.

Some parts of the Web app are protected using HTTPS -- specified in the
security contraints section of web.xml. 

When these protected pages are accessed, Tomcat automatically switches to
HTTPS (on port 8433).

However, how can I switch back to non-HTTPS (i.e., the "normal" port for the
Web app) when links to non-protected pages are subsequently selected? The
links generated by the <struts:link .> tag automatically retain the HTTPS
port number (8433) along with the domain name.

Thanks,

Frank Burns.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org