Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 servletContext 而不是请求以获得 requestDispatcher 有什么好处?
servletContext.getRequestDispatcher(dispatchPath)
并使用
argRequest.getRequestDispatcher(dispatchPath)
它在黑色和白色的 javadocs 中
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletRequest.html#getRequestDispatcher(java.lang.String)
该方法与 ServletContext.getRequestDispatcher(java.lang.String) 的区别在于该方法可以采用相对路径。
调用getRequestDispatcherfromServletContext时,需要提供绝对路径,但对于ServletRequest对象,则需要提供相对路径。
getRequestDispatcher
ServletContext
ServletRequest