You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by bu...@apache.org on 2003/07/09 20:14:56 UTC

DO NOT REPLY [Bug 21440] New: - whose target performs a 'forward' does not behave as expected

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21440>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21440

<jsp:include> whose target performs a 'forward' does not behave as expected

           Summary: <jsp:include> whose target performs a 'forward' does not
                    behave as expected
           Product: Tomcat 4
           Version: 4.1.24
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Jasper 2
        AssignedTo: tomcat-dev@jakarta.apache.org
        ReportedBy: pierre.delisle@sun.com
                CC: jan.luehe@sun.com


It appears that tomcat does not behave properly when a JSP
page invokes a <jsp:include> whose target performs a 'forward'.

Details below.

---
SETUP

Foo.html
 <!-- An HTML page that simply outputs "FOO" -->
 FOO

ForwardServlet.java:
 /**
  * A servlet that performs a RequestDispatcher.forward()
  * to "Foo.html".
  */
 package tsc.servlet;
 
 import java.io.IOException;
 import javax.servlet.*;
 
 public class ForwardServlet extends GenericServlet {
     public void service(ServletRequest req, ServletResponse res)
     throws ServletException, IOException {
      ServletContext context = getServletContext();              String
path="/Foo.html";
      RequestDispatcher rd = context.getRequestDispatcher(path);
      rd.forward(req, res);
     }
 }
Forward.jsp:
 <!-- A JSP page that performs a <jsp:forward> to "Foo.html". -->
 <jsp:forward page="Foo.html"/>

---
TestCase 1

With the following example:

 TestCase1.jsp
 -------------
 ***1***
 <jsp:include page="/ForwardServlet"/>   ***2***
 <% System.out.println("TestCase1.jsp"); %>

The expected result is that only "FOO" will be displayed
on the resulting page, and "TestCase1.jsp" will be
displayed on the console.

Here is why:

In JSP 5.4, it is stated that:
 "Inclusion is into the current value of out."
 ...
 "An included page only has access to the JspWriter object  and it cannot set
headers. This precludes invoking methods  like setCookie. Attempts to invoke
these methods will be ignored.  The constraint is equivalent to the one imposed on
 the include method of the RequestDispatcher class."

Although it would not hurt the spec to be a little more specific, the assumption
here is that the RequestDispatcher.include()
has to be called with a response object whose 'writer' is shared
with the "including" page.

Given that the target of the 'include' is a servlet that performs
a RequestDispather.forward(), the following will happen
(as per SRV 8.4):
  - output data in the response buffer is cleared
  - response content is sent and committed, and closed.

> From the viewpoint of our original TestCase1.jsp page, this therefore 

means that:
- "***1***" is added to the response output
- "***1***" gets cleared from the response output
- FOO is added to the response output
- the response output is closed
- '***2***' does not get added to the response output because
  it has already been closed
- The 'System.out()' statement gets executed.

If this example is run with Tomcat 4.1.24, the output
is:
 ***1***
 FOO
and "TestCase1.jsp" is NOT displayed on the console.
Not as expected.

---
Moreover, with the following example:

 TestCase2.jsp
 -------------
 ***1***
 <jsp:include page="/ForwardServlet"/>   ***2***
 <% System.out.println("TestCase2-a.jsp"); %>
 <jsp:include page="/ForwardServlet"/>   ***3***
 <% System.out.println("TestCase2-b.jsp"); %>

The expected result is that "TestCase2-a.jsp" will be displayed on the console
and that an IllegalStateException will be
thrown.
[Exception should be thrown because the response has already been committed with
the first forward (via the first include), and a forward
cannot be done (via the second include) when a response has already
been committed.]

If this example is run with Tomcat 4.1.24, the output
is:
 ***1***
 FOO
nothing is displayed on the console, and no exception is thrown.

---
Also, in the above two test cases, if ForwardServlet is replaced by
Forward.jsp as the target of the <jsp::include>'s:

TestCase1
 works as expected

TestCase2
 FOO
 "TestCase2-a.jsp" is displayed on the console  
 IllegalStateException is not thrown

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org