RE: include bug in 4.1.27

2003-11-05 Thread Holtfreter, Gregory

I have attached patches for two files which I believe fixes the problem I have 
described below. These are patches to the files from HEAD which would not address 
Tomcat 4.x but could be applied to the TOMCAT_4 branch also. 

Basically, the change I have made is to pass the application variable from the 
compiled JSP to the JspRuntimeLibrary.include(...) method and use it, if not null, to 
obtain a RequestDispatcher, otherwise use the request as before.
 

-Original Message-
From: Holtfreter, Gregory 
Sent: Tuesday, November 04, 2003 1:03 PM
To: [EMAIL PROTECTED]
Subject: jsp:include bug in 4.1.27



I am currently porting webapps to Tomcat(4.1.27) from WL and believe I may have found 
a bug with the 
implementation of the jsp:include action tag. The problem I found is that when using 
the jsp:include tag in a page which resides in a context which differs from the 
request's initial context the page being included is not found. (The crossContext 
attribute of the Context element has been set to true.) 

An example may better explain this:

WebappOne
one.jsp source:
WebappOne/one.jspbr
% 
config.getServletContext().getContext(/WebappTwo).getRequestDispatcher(/two.jsp).include(request,response);
 %

WebappTwo
two.jsp source:
WebappTwo/two.jspbr
jsp:include page=/three.jsp flush=true/

three.jsp source:
WebappTwo/three.jsp 


The text inside of WebappTwo/three.jsp will not be included in WebappTwo/two.jsp 
output when requesting WebappOne/one.jsp. However, if we move WebappTwo/three.jsp to 
WebappOne the output is included in the output of WebappTwo/two.jsp. 

I think that the cause of this is that JspRuntimeLibrary.include(...) uses the request 
to obtain a RequestDispatcher and the request is pointing to the initial context:

RequestDispatcher rd = request.getRequestDispatcher(resourcePath);
rd.include(request, new ServletResponseWrapperInclude(response, out));

The JSP 1.2 spec seems to say that jsp:include should be relative to the current page:

A jsp:include .../ element provides for the inclusion of static and dynamic
resources in the same context as the current page.

Thanks,
Greg Holtfreter
Software Engineer
Encyclopaedia Britannica  


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Index: jasper2/src/share/org/apache/jasper/compiler/Generator.java
===
RCS file: 
/home/cvspublic/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
retrieving revision 1.214
diff -u -r1.214 Generator.java
--- jasper2/src/share/org/apache/jasper/compiler/Generator.java 20 Oct 2003 21:07:46 
-  1.214
+++ jasper2/src/share/org/apache/jasper/compiler/Generator.java 5 Nov 2003 17:35:59 
-
@@ -934,7 +934,7 @@
 }
 
 out.printin(
-org.apache.jasper.runtime.JspRuntimeLibrary.include(request, 
response, 
+org.apache.jasper.runtime.JspRuntimeLibrary.include(request, 
response, application, 
 + pageParam);
 printParams(n, pageParam, page.isLiteral());
 out.println(, out,  + isFlush + ););
Index: jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java
===
RCS file: 
/home/cvspublic/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java,v
retrieving revision 1.25
diff -u -r1.25 JspRuntimeLibrary.java
--- jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java  4 Nov 2003 
19:28:49 -   1.25
+++ jasper2/src/share/org/apache/jasper/runtime/JspRuntimeLibrary.java  5 Nov 2003 
17:34:11 -
@@ -75,6 +75,7 @@
 
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 import javax.servlet.http.HttpServletRequest;
@@ -965,7 +966,6 @@
 
 }
 
-
 /**
  * Perform a RequestDispatcher.include() operation, with optional flushing
  * of the response beforehand.
@@ -973,14 +973,26 @@
  * @param request The servlet request we are processing
  * @param response The servlet response we are processing
  * @param relativePath The relative path of the resource to be included
- * @param out The Writer to whom we are currently writing
+ * @param out The JspWriter to whom we are currently writing
  * @param flush Should we flush before the include is processed?
  *
  * @exception IOException if thrown by the included servlet
  * @exception ServletException if thrown by the included servlet
  */
-public static void include(ServletRequest request,
-   

Re: include bug in 4.1.27

2003-11-05 Thread Remy Maucherat
Holtfreter, Gregory wrote:

I have attached patches for two files which I believe fixes the
problem I have described below. These are patches to the files from
HEAD which would not address Tomcat 4.x but could be applied to the
TOMCAT_4 branch also.
Basically, the change I have made is to pass the application variable
from the compiled JSP to the JspRuntimeLibrary.include(...) method
and use it, if not null, to obtain a RequestDispatcher, otherwise use
the request as before.
There are a few issues with cross context in Tomcat 4.1.x. If you want 
the right behavior (session handling + usage of the methods from the 
request object), you have to use Tomcat 5.0 (ex: Tomcat 5.0.14). The 
changes to get that working were rather extensive.

Rémy



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]