为什么
ServletRequest接口的getRequestDispatcher(String path)不能扩展到当前servlet上下文之外
在哪里
ServletContext的getRequestDispatcher(String path)可以使用getContext(String uripath)方法为外部上下文中的资源获取RequestDispatcher.
如何??
请帮忙
ZZ *_*der 38
如果使用绝对路径,如("/index.jsp"),则没有区别.
如果使用相对路径,则必须使用HttpServletRequest.getRequestDispatcher().ServletContext.getRequestDispatcher()不允许.
例如,如果您收到了您的请求http://example.com/myapp/subdir,
RequestDispatcher dispatcher =
request.getRequestDispatcher("index.jsp");
dispatcher.forward( request, response );
Run Code Online (Sandbox Code Playgroud)
将请求转发到页面http://example.com/myapp/subdir/index.jsp.
在任何情况下,您都不能将请求转发到上下文之外的资源.