◆ HttpServletResponse.sendRedirect(String)
参数可以指定为相对路径、绝对路径或其它Web应用。
假设通过http://localhost/myApp/cool/bar.do 请求到达该方法所属的Servlet。
相对路径:response.sendRedirect("foo/stuff.do")
容器相对于原来请求URL的目录加参数来生成完整的URL——http://localhost/myApp/cool/foo/stuff.do。
绝对路径:response.sendRedirect("/foo/stuff.do")
容器相对于Web应用本身加参数建立完整的URL——http://localhost/foo/stuff.do。
其它Web应用:response.sendRedirect("http://www.xxx.com ")
容器直接定向到该URL。
◆HttpServletRequest.getRequestDispatcher(String)
参数可以指定为相对路径或绝对路径。
相对路径情况下生成的完整URL与重定向方法相同。
绝对路径与Servlet重定向不同,容器将相对于Web应用的根目录加参数生成完整的URL,即:
request.getRequestDispatcher("/foo/stuff.do")生成的URL是http://localhost/myApp/foo/stuff.do 。
◆ ServletContext.getRequestDispatcher(String)
参数只能指定为绝对路径,生成的完整URL与HttpServletRequest.getRequestDispatcher(String)相同。