tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ciAnd7 <>
Subject Request.getContextPath() after RequestDispatcher.forward()
Date Mon, 03 Mar 2008 16:58:23 GMT

I am using tomcat 6.0.13 on linux.
I try to deploy my application in to the root context. I.e. it should be
available as root application on one of  virtual host (http://vhost1/). So,
I add <Context ... path="/" /> into the server.xml (I know, it is not
recommended to do it in server.xml, but it is simple and I just want to do
simple testing right now).
The application works fine. But there is a problem with
request.getContextPath() method.  
My Servlets use RequestDispatcher.forward() to JSP. And then, JSP use
Request.getContextPath() to generate URLs (more precisely, getContextPath()
used by JSTL`s <c:url ..> implementation). 
But getContextPath() returns "/", so urls generated by <c:url> looks like
"//image/blah.gif" - i.e. they have double leading slashes. As result -
browser can`t process urls correctly. As I understand specification,
getContextPath() should returns empty string in such case... (And JSTL`s
implementation  of <c:url> expects such behavior).

If I deploy application under "ordinal" context path, all works correctly
(getContextPath() returns string like "/myapp").
If my Servlet use RD.include() instead of forward(), all works fine:
getContextPath() returns empty string.

Could somebody help me with solution.


View this message in context:
Sent from the Tomcat - User mailing list archive at

To start a new topic, e-mail:
To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message