[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index] [Home]

Problem with included include


Hi!

I've got a problem with included includes. Please see test 194.
GNUJSP assumes that getServletPath() reflects the URL used in
getRequestDispatcher(URL), but not the URL of the original request. This
is the way jo! 0.9.3a (and probably other engines) work.
The reason for that is, that the spec 2.1a is a bit unprecise on that
topic (page 20):

"The request object passed to the target object will reflect the request
URL path and
path info of the calling request."

Now what does this mean? A hint is provided in spec 2.2pr2 (page 40,
8.3.1):

"When a servlet is being used from within an include, it is sometimes
necessary for that servlet to
know the path by which it was invoked and not the original request
paths. The following request
attributes are set:
javax.servlet.include.request_uri
javax.servlet.include.context_path
javax.servlet.include.servlet_path
javax.servlet.include.path_info
javax.servlet.include.query_string
These attributes are accessible from the included servlet via the
getAttribute method on the
request object."

Implicitly this means that the methods getServletPath() etc. shouldn't
return anything else than the original request. So when you include an
include you can't rely on the methods, but you have to check the
appropriate attributes.

To make a long mail short: In PageContextImpl the method findURI should
be changed.
Suggestion:

--- CODE BEGIN ---
    private String findURI(String relativeURI) {

 if (relativeURI.startsWith("/")) return relativeURI; // not so relative

 // pathInfo attribute is honored by JServ 1.0, Jigsaw 2.0.3
 String currentURI = ((HttpServletRequest) request).getPathInfo();

 // Check for request attributes (servlet api 2.2)
 if ((currentURI == null) || ("".equals(currentURI))) {
     currentURI =
(String)request.getAttribute("javax.servlet.include.servlet_path");
 }

 // WebApp jo! for example
 if ((currentURI == null) || ("".equals(currentURI))) {
     currentURI = ((HttpServletRequest) request).getServletPath();
 }

 int pos = currentURI.lastIndexOf('/');
 if (pos == -1)
     throw new IllegalArgumentException(

JspConfig.getLocalizedMsg(ERR_gnujsp_cannot_interpret_pathinfo));
 return (currentURI.substring(0, pos + 1) + relativeURI);
    }
--- CODE END ---

Comments?

-hendrik
- - - - - - - - - - - - - - - - - - - - - - - - - - -
  The WebApp Framework        http://www.webapp.de/
  jo!                 small&smart 2.1 servletengine
  Persistence              objectrelational mapping
  Java Server & Servlets    The German servlet book