I am using a class which implements Filter for my jsp stuff. It looks like this:
public class MyFilter implements Filter
{
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
request.getRequestDispatcher("mypage.jsp").forward(request, response);
}
}
So the target, "mypage.jsp",开发者_开发百科 is just sitting in my top-level directory. The filter works fine if I'm entering urls like:
http://www.mysite.com/foo
http://www.mysite.com/boo
but if I enter a trailing slash, I'll get a 404:
http://www.mysite.com/foo/
http://www.mysite.com/boo/
HTTP ERROR: 404
/foo/mypage.jsp
RequestURI=/foo/mypage.jsp
it seems if I enter the trailing slash, then the filter thinks I want it to look for mypage.jsp in subfolder foo or boo, but I really always want it to just find it at:
http://www.mysite.com/mypage.jsp
how can I do that?
Thank you
Make the request dispatcher path absolute - use "/mypage.jsp" rather than "mypage.jsp". The resource is then resolved from the root of the webapp context.
精彩评论