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: Cant 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
Only after the statement is executed