Sorry if I'm missing something, but I believe this thread started with
a quetsion about why <jsp:include> of a page that does a redirect
doesn't cause the request to be redirected. The answer to this is that
an included page (using <jsp:include> or pageContext.include()) is not
allowed to set headers. If it does, the headers are silently ignored.
The include mechanism is only for including the body content produced
by the included page.
If you want to redirect from a JSP page, use this code in the main page:
response.sendRedirect("nextPage.jsp");
either in a scriptlet or in a simple custom action.
Hans
Jay Burgess wrote:
> O.K., I'm off to the Tomcat list to pursue this further. I found the
> following function in the Tomcat source, and am wondering whether it's the
> root of my problem, and if so, why it's written this way.
>
> /**
> * Disallow <code>sendRedirect()</code> calls on an included response.
> *
> * @param location The new location
> *
> * @exception IOException if an input/output error occurs
> */
> public void sendRedirect(String location) throws IOException {
> if (!included)
> ((HttpServletResponse) getResponse()).sendRedirect(location);
> }
>
> BTW, Telnet simply showed what we expected--status 200, no Location header
> set, and nothing where the <JSP:INCLUDE> should have been.
>
> Thanks again.
>
> Jay
>
> > -----Original Message-----
> > From: Jay Burgess [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, May 20, 2002 10:32 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: sendRedirect() from within a <jsp:include>?
> >
> >
> > The mystery thickens. I just added "res.isCommitted()" right before my
> > sendRedirect(), and it returns false. So it appears that the
> > response is
> > not being committed (which is what we expect), yet the
> > sendRedirect() is
> > simply being ignored.
> >
> > I'll try your Telnet suggestion now and see what comes back. I'm also
> > going to try mimic'ing sendRedirect() by setting the headers
> > by hand, and
> > see if there's any difference.
> >
> > Thanks for the input.
> >
> > Jay
> >
> > > -----Original Message-----
> > > From: Joseph Ottinger [mailto:[EMAIL PROTECTED]]
> > > Sent: Monday, May 20, 2002 10:16 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: Re: sendRedirect() from within a <jsp:include>?
> > >
> > >
> > > It wouldn't surprise me to see a bug in Tomcat, since I run
> > > up against a few
> > > of them all the time. :)
> > >
> > > Anyway, it's easy to figure out what's happening: telnet to
> > > the server/port,
> > > do a simple GET on your page that has the redirect, and read
> > > the headers.
> > > You'd expect the buffering to work, yes. (I certainly would.)
> > > You should
> > > also be pessimistic as to whether it does or not, esp. if
> > > what you expect
> > > isn't happening when you know it should.
> > >
> > > As far as the clue level... well, you're in JSP-I, where the
> > > clues are few
> > > and far between. If you make an assumption that everyone who
> > > posts anything
> > > is generally clueless, nineteen times out of twenty, you're
> > > likely to be
> > > right. :)
> > >
> > > >From: Jay Burgess <[EMAIL PROTECTED]>
> > >
> > > >Gah!? You seem to imply that I don't understand the how
> > the redirect
> > > >actually works. I do. But my understanding from the JSP
> > > spec is that the
> > > >container is supposed to provide an 8kb buffer by default (Section
> > > >JSP.2.10.1), so the six bytes that make up the string
> > > "<HTML>" should not
> > > >be sent down the line. I'm supposed to have the ability to do a
> > > >sendRedirect() in this case.
> > > >
> > > >I'm using Tomcat 4.0.3, by the way, and since it's
> > supposed to be the
> > > >Reference Implementation, I assumed it would work. I
> > find it hard to
> > > >believe that this is a bug in Tomcat, as it's such base
> > > functionality.
> > > >
> > > >Other ideas?
> > > >
> > > >Jay
> > > >
> > > > > -----Original Message-----
> > > > > From: Joseph Ottinger [mailto:[EMAIL PROTECTED]]
> > > > > Sent: Monday, May 20, 2002 5:50 AM
> > > > > To: [EMAIL PROTECTED]
> > > > > Subject: Re: sendRedirect() from within a <jsp:include>?
> > > > >
> > > > >
> > > > > Gah! The problem is that sendRedirects have to take place
> > > > > before any output
> > > > > is spooled to the client. It's a HEADER. One would hope your
> > > > > container would
> > > > > massage the output and cache the body content until it needs
> > > > > to send it down
> > > > > the line, but apparently it's not doing that.
> > > > >
> > > > > Thus, the <html> is the problem.
> > > > >
> > > > >
> > > > > >From: Bhushan_Bhangale <[EMAIL PROTECTED]>
> > > > > >Reply-To: A mailing list about Java Server Pages
> > > specification and
> > > > > >reference <[EMAIL PROTECTED]>
> > > > > >To: [EMAIL PROTECTED]
> > > > > >Subject: Re: sendRedirect() from within a <jsp:include>?
> > > > > >Date: Mon, 20 May 2002 15:40:23 +0530
> > > > > >
> > > > > >Before the forward call you should not write anything to
> > > the response
> > > > > >object. If you will write anything to response object and
> > > > > then you will
> > > > > >forward to some other URL then you will always get the error.
> > > > > >
> > > > > >-----Original Message-----
> > > > > >From: Jay Burgess [mailto:[EMAIL PROTECTED]]
> > > > > >Sent: Friday, May 17, 2002 9:57 PM
> > > > > >To: [EMAIL PROTECTED]
> > > > > >Subject: sendRedirect() from within a <jsp:include>?
> > > > > >
> > > > > >
> > > > > >Obviously I'm missing some important detail about the
> > > > > mechanics of using
> > > > > ><jsp:include>.
> > > > > >
> > > > > >I've got a JSP with nothing in it but a
> > > > > >"<html><jsp:include>,,,</jsp:include></html>". The
> > > "page" for the
> > > > > ><jsp:include> is a direct call to my servlet. The only
> > > > > thing my servlet
> > > > > >does is a sendRedirect() to another page.
> > > > > >
> > > > > >When I request my JSP, I get back just "<html></html>",
> > > > > which means the
> > > > > >redirect failed, the <jsp:include> did nothing, and I
> > > didn't get any
> > > > > >exceptions (like an IllegalStateException showing the
> > > > > response was already
> > > > > >committed).
> > > > > >
> > > > > >What am I missing about trying to do things this way?
> > > BTW, I'm using
> > > > > >Tomcat 4.0.3.
> > > > > >
> > > > > >Jay
> > > > > >
> > > > > >=============================================================
> > > > > ==============
> > > > > >To unsubscribe: mailto [EMAIL PROTECTED] with
> > body: "signoff
> > > > > >JSP-INTEREST".
> > > > > >For digest: mailto [EMAIL PROTECTED] with body: "set
> > > JSP-INTEREST
> > > > > >DIGEST".
> > > > > >Some relevant FAQs on JSP/Servlets can be found at:
> > > > > >
> > > > > > http://archives.java.sun.com/jsp-interest.html
> > > > > > http://java.sun.com/products/jsp/faq.html
> > > > > > http://www.esperanto.org.nz/jsp/jspfaq.jsp
> > > > > > http://www.jguru.com/faq/index.jsp
> > > > > > http://www.jspinsider.com
> > > > > >
> > > > > >=============================================================
> > > > > =============To
> > > > > >unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> > > > > >JSP-INTEREST".
> > > > > >For digest: mailto [EMAIL PROTECTED] with body: "set
> > > JSP-INTEREST
> > > > > >DIGEST".
> > > > > >Some relevant FAQs on JSP/Servlets can be found at:
> > > > > >
> > > > > > http://archives.java.sun.com/jsp-interest.html
> > > > > > http://java.sun.com/products/jsp/faq.html
> > > > > > http://www.esperanto.org.nz/jsp/jspfaq.jsp
> > > > > > http://www.jguru.com/faq/index.jsp
> > > > > > http://www.jspinsider.com
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > -----------------------------------------------
> > > > > Joseph B. Ottinger [EMAIL PROTECTED]
> > > > > http://enigmastation.com IT Consultant
> > > > >
> >
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
> DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://archives.java.sun.com/jsp-interest.html
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.jsp
> http://www.jguru.com/faq/index.jsp
> http://www.jspinsider.com
>
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
JavaServer Pages http://TheJSPBook.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://archives.java.sun.com/jsp-interest.html
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.jsp
http://www.jguru.com/faq/index.jsp
http://www.jspinsider.com