There are about three redirect Methods Using JSP:
1. response. sendredirect ();
2. response. setheader ("location ","");
3. <JSP: Forward page = ""/>
The following rules are obtained after testing:
I. response. sendredirect ()
Out. Flush () is not allowed before this statement. If yes, an exception occurs:
Java. Lang. illegalstateexception: Can't sendredirect () after data has committed to the client.
At com. Caucho. server. Connection. abstracthttpresponse. sendredirect (abstracthttpresponse. Java: 558)
...
Browser address bar changes after jump
If you want to jump to different hosts, after the jump, the statement after this statement will continue to be executed, as if a new thread, but the response operation has no significance;
If you want to jump to the same host, the statement after this statement is executed will not jump;
2. response. setheader ("location ","")
No out. Flush () is allowed before this statement. If yes, the page will not jump.
Browser address bar changes after jump
Only after the statement is executed
Iii. <JSP: Forward page = ""/>
Out. Flush () is not allowed before this statement. If yes, an exception occurs:
Java. Lang. illegalstateexception: Forward () not allowed after buffer has committed.
At com. Caucho. server. webapp. requestdispatcherimpl. Forward (requestdispatcherimpl. Java: 134)
At com. Caucho. server. webapp. requestdispatcherimpl. Forward (requestdispatcherimpl. Java: 101)
At com. Caucho. jsp. pagecontextimpl. Forward (pagecontextimpl. Java: 836)
...
The browser address bar remains unchanged after the jump, but the address bar can only jump to the current host
The statement after this statement is executed is not redirected.