sendRedirect重定向中起始/的含义是servlet容器的根路径,一般是http://localhost:8080/
请求转发中的起始/是?
文档:
sendRedirect
void sendRedirect(String location) throws IOException
-
Sends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
-
-
Parameters:
-
location
- the redirect location URL
-
getRequestDispatcher
RequestDispatcher getRequestDispatcher(String path)
-
Returns a
RequestDispatcher
object that acts as a wrapper for the resource located at the given path. ARequestDispatcher
object can be used to forward a request to the resource or to include the resource in a response. The resource can be dynamic or static.The pathname specified may be relative, although it cannot extend outside the current servlet context. If the path begins with a "/" it is interpreted as relative to the current context root. This method returns
null
if the servlet container cannot return aRequestDispatcher
.The difference between this method and
ServletContext.getRequestDispatcher(java.lang.String)
is that this method can take a relative path. -
-
Parameters:
-
path
- aString
specifying the pathname to the resource. If it is relative, it must be relative against the current servlet.
Returns:
-
a
RequestDispatcher
object that acts as a wrapper for the resource at the specified path, ornull
if the servlet container cannot return aRequestDispatcher
-