https://issues.apache.org/bugzilla/show_bug.cgi?id=46131
Summary: for a root context getContextPath returns "/" after a
forward
Product: Tomcat 6
Version: 6.0.18
Platform: PC
OS/Version: Windows XP
Status: NEW
Severity: normal
Priority: P2
Component: Servlet & JSP API
AssignedTo: [email protected]
ReportedBy: [EMAIL PROTECTED]
Javadoc for HttpServletRequest#getContextPath() says:
For servlets in the default (root) context, this method returns ""
As long as i do no forward Tomcat does it right.
However, when forwarding via a Filter to another resource the result of
getContextPath() changes from "" to "/".
Small demo code:
public class TestFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain
chain) {
String path = ((HttpServletRequest)req).getContextPath();
System.out.println("Filter context path:" + path);
//prints ""
RequestDispatcher disp = req.getRequestDispatcher("/testservlet");
disp.forward(request, response);
}
...
}
public class TestServlet extends HttpServlet {
public void service(ServletRequest req, ServletResponse res) {
String path = ((HttpServletRequest)req).getContextPath();
System.out.println("Servlet context path:" + path);
//prints "" but when coming from filter prints "/"
}
}
Small issue but i've had big problems when using JSF (myfaces) and
UrlRewriteFilter for a root context application.
As long as no rewriterule matches, JSF generates URLs like "/path/to/file.jsf"
which the browser interprets as "http://www.myhost.com/path/to/file.jsf".
But when a rewriterule matches (and a forward is processed)
JSF generates URLs like "//path/to/file.jsf" which the browser interprets as
"http://path/to/file.jsf"
My workaround:
A HttpServletRequestWrapper which overrides getContextPath()
public String getContextPath() {
return "/".equals(super.getContextPath()) ? "" : super.getContextPath();
}
--
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]