如果使用诸如(
"/index.jsp")之类的绝对路径,则没有区别。
如果使用相对路径,则必须使用
HttpServletRequest.getRequestDispatcher()。
ServletContext.getRequestDispatcher()不允许。
例如,如果您在收到请求
http://example.com/myapp/subdir,
RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp"); dispatcher.forward( request, response );将请求转发到页面
http://example.com/myapp/subdir/index.jsp。
无论如何,您都不能将请求转发到上下文之外的资源。



