sendRedirect只能在servlet容器中才能执行,详见API:----------------------------------------------------------------sendRedirect public void sendRedirect(java.lang.String location) throws java.io.IOExceptionSends 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 Throws: java.io.IOException - If an input or output exception occurs IllegalStateException - If the response was committed
这个方法只能用一次, sendRedirect以后,控制权就转移到下一个页面上了,此页面的response就已经失效了---------------------- 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.
public void sendRedirect(java.lang.String location)
throws java.io.IOExceptionSends 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
Throws:
java.io.IOException - If an input or output exception occurs
IllegalStateException - If the response was committed
sendRedirect以后,控制权就转移到下一个页面上了,此页面的response就已经失效了----------------------
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.