The servlet handles the business logic, the JSP handles the view rendering, and the servlet processes the request, and the result of the output goes to the workaround of the JSP page

Source: Internet
Author: User

After the servlet processes the request, the request is typically redirected or forwarded for processing.

(dispatcher) Request forwarding: Also known as Server end multiplicity orientation, refers to the server in the process of processing multiple request requests, successively commissioned multiple JSP

The process of succession processing. It is implemented by means of dispatcher, requestdispatchers, one is forward and the other is include. The corresponding JSP implements the dispatch tag also has two:<jsp:forward/> and <jsp:include/>

The servlet jumps to the JSP, and the request to reponse is always delivered, which is key. Request and reponse can be viewed as a resource, and a series of servlets and JSPs are calculated based on the same resource to complete their responsibilities.

Often used: Request.getrequestdispatcher ("/xxxx.jsp"). Forward (request, response); To handle forwarding

(Redirect) Redirection: referred to as client redirection, refers to HTTP redirection. When the client sends a request to the server, it asks for a resource. After the server receives this request, it discovers that the requested resource is actually stored in another location, and the server writes the correct URL of the requested resource in the returned response. and set the status code of Reponse to 301 (indicating that this is a response that requires browser redirection), and when the client accepts this response the request will be re-initiated according to the new URL. Redirection has a typical syndrome, that is, when a request is redirected, the URL that is displayed on the final browser is no longer the URL that was requested at the beginning. This is the origin of redirection.

Common: Generally we want to write according to our web app name, such as redirect to login.jsp in Webroot root directory, we can write this, Response.sendredirect ("/web app name/login.jsp"); So there's a bug that when you change the name of the Web app, the jump fails, so the Web app name can't be written dead, and we know that Request.getcontextpath () can get the name of the Web app, So can write Response.sendredirect ("" +request.getcontextpath () + "/login.jsp");

After the servlet processes the request, it is necessary to use JavaScript technology to have the servlet connect to another servlet.

Response.setcontenttype ("Text/html;charset=utf-8");//here is to prevent garbledresponse.getwriter (). Print ("<script> location.href=" "+request.getcontextpath () +"/servlet/ Xxxxxxservlet '; </script> ");     4. In another case, when a JSP page is forwarded by a servlet request, in this JSP page, if you want to visit another servlet, this is the only way to write:<script> location.href= ' Xxxxxxservlet '; </script> "So it's OK. There is also a very important point, because all the files under the Web-inf directory are protected, so the files in the Web-inf directory to exchange visits can only be implemented in the SSH technology, or only through the servlet to achieve mutual visits.

The servlet handles the business logic, the JSP handles the view rendering, and the servlet processes the request, and the result of the output goes to the workaround of the JSP page

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.