Servlet:
Of course, in servlet, the jump usually occurs in methods such as doget and dopost.
1) Redirect Mode
Response. sendredirect ("/a. jsp ");
The path of the page is relative. Sendredirect can jump the page to any page, which may not be limited to this web application, for example:
Response. sendredirect ("http://www.ycul.com ");
The browser address bar changes after the jump.
In this way, values can only be transmitted with parameter in the URL or in the session. Request. setattribute cannot be used.
2) forward mode
Requestdispatcher dispatcher = request. getrequestdispatcher ("/a. jsp ");
Dispatcher. Forward (request, response );
The path of the page is relative. The forward method can only jump to the page in this web application.
The browser address bar does not change after the jump.
In this way, you can use three methods for transferring values: URL with parameter, session, request. setattribute
JSP:
1) response. sendredirect ();
It is the same as Servlet's response. sendredirect () method.
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
3)
NO out is allowed before this statement. flush (). 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)
...
after the jump, the browser address bar remains unchanged, but the jump can only be made to the current host
after the statement is executed, the jump will be made