How to Implement page Jump in servlet

Source: Internet
Author: User

How to Implement page Jump in servlet

Client jump

// Use sendredirect of the response object to redirect the client

// Servlet doget Method
Public void doget (https tutorial ervletrequest req, httpservletresponse res)
Throws servletexception, ioexception {
Printwriter out = res. getwriter ();
Out. println ("hello world! ");
Res. sendredirect ("test. do"); // servlet jump (client jump)
}


Client jump cannot pass parameters like the target page (if you need to pass parameters to the target page using this method, you can use the session object to record the parameter values, which are not detailed here)


Server jump

// Use the requestdispatcher interface to redirect the server and pass parameters to the target page

Public void doget (httpservletrequest req, httpservletresponse resp)
Throws servletexception,
Ioexception {
Printwriter out = resp. getwriter ();



/*
* Server jump is implemented in servlet and parameters are passed to the jump page
*/

Req. setattribute ("name", "haiyun"); // Add parameters for the request object
Requestdispatcher dispatcher = req. getrequestdispatcher ("test-04.jsp tutorial"); // get the requestdispatcher object using the req object
Dispatcher. forward (req, resp); // use the requestdispatcher object to jump to the target path on the server side

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.