The difference between forward () and Sendredirect () in JSP

Source: Internet
Author: User

There are two methods for JSP page jumps: the Requestdispatcher.forward () method and the Httpservletresponse.sendredirect () method.

The difference between them is:

Requestdispatcher.forward () method is only a control in the container of the steering, in the client browser address bar will not show the turn of the address, he will not change the value of the request, if you need to be in the next page to get new information from the words, You can Request.setattribute () to place some flags so that they are retrieved from the next page. The wording reads as follows:

try{
  request.getRequestDispatcher("display.jsp").forward(request,response);
}

catch(Exception e){

  e.printStackTrace();

}

Httpservletresponse.sendredirect () is a complete jump, the browser will get the address of the jump, and resend the request link. In this way, you can see the link address after the jump from the address bar of the browser. The wording reads as follows:

Response.sendredirect ("display.jsp");

In contrast, the Requestdispatcher.forward () method is more efficient, using the request Dispatcher.forward () method as much as possible when it meets the needs, and it also helps to hide the actual links.

Related Article

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.