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 2005/01/24 18:39:11 UTC
DO NOT REPLY [Bug 33223] New: -
pageContext.forward and result in StringIndexOutOfBoundsException
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33223>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=33223
Summary: pageContext.forward and <jsp:include> result in
StringIndexOutOfBoundsException
Product: Tomcat 5
Version: 5.5.4
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: normal
Priority: P2
Component: Jasper
AssignedTo: tomcat-dev@jakarta.apache.org
ReportedBy: David.Biesack@sas.com
We have a tag library which we use on JSP pages. The Page tag forwards to a
controller (via pageContext.forward() which then redirects to a template page
and the template page includes via <jsp-include> the site navigation etc. then
includes via <jsp-include> the original request page. This works in Tomcat 4
but it throws an exception in Tomcat 5 - I tried with 5.5.4.
In debugging this, I found the problem is JspServlet:service which tries to call
if (requestUri != null){
String currentIncludedUri
= requestUri.substring(requestUri.indexOf(includeUri));
with the values:
includeUri= "/test/index.jsp"
requestUri= "/tomcat-bug/test/"
Since includeUri does not appear in requestUri, indexOf returns -1 and this
causes a runtime exception.
This occurs because my webapp has index.jsp in the web.xml welcome-file-list,
but when the initial page is being executed, request.getRequestURI() returns the
requested page, not the resolved welcome page. For example,
Here is a simplified example showing how to reproduce. I deployed this in the
webapp context "tomcat-bug" on Tomcat 5.5.4 with no front end web server -
Tomcat is running as the web server. I removed the tag libraries and other
infrastructure and created simple JSP files that demonstrate the root problem,
so no classes or jars are required in WEB-INF/lib or WEB-INF/classes.
URL: http://localhost:8080/tomcat-bug/test/
Note: I don't get the exception with the URL
http://localhost:8080/tomcat-bug/test/index.jsp, only when the page is resolved
via the welcome-file
Web application files:
test/index.jsp:
<%
Boolean included = (Boolean) pageContext.getAttribute("template.running",
PageContext.REQUEST_SCOPE);
if (included == null)
{
String uri = request.getRequestURI();
String path = request.getContextPath();
if (path != null && uri.startsWith(path))
uri = uri.substring(path.length());
pageContext.setAttribute("template.body", uri, PageContext.REQUEST_SCOPE);
pageContext.forward("/templates/template.jsp");
}
else
{
%>
<p>This is my JSP page, test/index.jsp. This is the body/content of the page.</p>
<%
}
%>
<!-- end of test/index.jsp -->
templates/template.jsp:
<%
pageContext.setAttribute("template.running", Boolean.TRUE,
PageContext.REQUEST_SCOPE);
String top = "/templates/top.jsp";
String body = (String) pageContext.getAttribute("template.body",
PageContext.REQUEST_SCOPE);
%>
<html>
<head><title>Tomcat bug</title></head>
<body>
<jsp:include flush="true" page="<%=top%>"></jsp:include>
<br/>
Body:
<jsp:include flush="true" page="<%=body%>"></jsp:include>
:body
</body>
</html>
<!-- end of templates/template.jsp -->
templates/top.jsp :
<p>This is the top navigation bar for the page template (top.jsp)<p>
<!-- end of templates/top.jsp -->
WEB-INF/web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org