Methods for redirecting in servlet and JSP __jsp

Source: Internet
Author: User

A. Requestdispatcher.forward ():

is the server-side effect. When using forward (), the Servlet container passes HTTP requests from the current servlet or JSP to another servlet,jsp or normal HTML file, which means that your form is submitted to a.jsp and forward () is used in a.jsp. Redirect to B.jsp. All information submitted by Form at this time is available in b.jsp, and parameters are automatically passed.

Forward () cannot be redirected to a JSP file with a frame, which can be redirected to an HTML file with a frame, while forward () cannot be passed back with parameters such as Servlet?name=frank, which is not possible. You can pass Response.setattribute ("name", name) to the next page within your program.

The browser address bar URL does not change after redirection. Typically used in a servlet and not used in a JSP.

B . Response.sendredirect ()

is working on the user's browser side. Sendredirect () can be passed with parameters, such as Servlet?name=frank to the next page, and it can be redirected to different hosts, Sendredirect () can redirect the JSP file with frame.

After redirection, the URL of the redirected page appears on the browser's address bar.

C . <jsp:forward page= ""/>

Its underlying part is implemented by RequestDispatcher, so it carries the imprint of the Requestdispatcher.forward () method if there is a lot of output before <jsp:forward>, the previous output has the buffer full, will be automatically exported to the client, the statement will not work, and this should be particularly noted. Also note: It can not change the browser address, the refresh will result in duplicate submission

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.