JSP and servlet jump to each other summary

Source: Internet
Author: User

JSP jumps to the servlet:

1.<jsp:forward page= "url" ></jsp:forward> note that the URL here cannot directly write your servlet name, but to fill out the url-pattern of the servlet in Web.xml, namely "/xxxservlet" form. There are slashes, slashes, staves. In addition, this way directly jumped away, in the servlet write jump back to the original page of the statement, will be an error java.io.IOException:Stream closed.

2.<jsp:include page= "url" ><jsp:param name= "xx" value= "xx"/></jsp:include> ditto, the URL has a slash. The advantage of this approach is that the servlet does not have to write a jump statement and will automatically return to the original page because it is a dynamic include File command. In addition, this method can also pass multiple parameters, you know.

3. Use JavaScript. such as <script type= "Text/javascript" >window.location= "Xxxservlet" </script>


Servlet jumps to JSP

1.response.sendredirect ("URL") the browser address bar changes after the jump. You can jump to any page, not necessarily limited to this web application.
This way to pass the value out, you can only in the URL with parameter or in the session, can not use Request.setattribute to pass.

2.request.getrequestdispatcher ("/a.jsp"). Dispatcher. Forward (request, response);
The path to a servlet page jump is a relative path. The forward method can only jump to a page in this Web application. The browser address bar will not change after the jump.
Use this way to jump, the value can be used in three ways: URL with Parameter,session,request.setattribute

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.