Common built-in objects in JSP (5) Small summary and two kinds of page jump mode (server-side switch, client jump) difference

Source: Internet
Author: User
Tags tomcat server

several built-in objects commonly used in JSPs:I. Request Object

Main functions:
(1) Get information on the request page
For example: Request.getparameter ("parameter name");
(2) Get information about the client
For example: Request.getremoteaddr ();//Gets the IP address of the client.
(3) Handling garbled characters
For example: request.setcharacterencoding ("UTF-8");

Second, Response object

Main functions:
(1) Request redirection (client jump)
Response.sendredirect ("URL address of the destination");
(2) Send a message to the browser
For example, set the browser's default encoding: Response.setheader ("Content-type", "text/html;charset=utf-8");
Response.setcharacterencoding ("UTF-8");
(3) Cookies can be set

Third, out object

Main functions:
Server-side output content to the client, for example, Out.print ("Hello <br>");

Iv. Session object (one full reply)

Main functions:
(1) The transfer of attribute values within the session range.
(2) Determine if this answer is a new reply. Session.isnew ();

V. Application object (one completed operation of the project)

Main functions:
(1) Gets the absolute path that the project deploys to the Web server.
(2) The implementation of the website counter
(3) Transfer of attributes within the application range

the difference between two kinds of jumpsOne

1, server-side jump (with forward words)
1) in the a.jsp file
<jsp:forward url= "b.jsp" >
2) in servlet, implement server-side jump ********
Request.getrequestdispater ("Destination Path"). Forward (Request,response);
2, the client's jump
If you are in the a.jsp file
(1) <a href= "b.jsp" > click to jump </a>
(2) <form action= "b.jsp" method= "POST" ></form>
(3) Response.sendredirect ("b.jsp");
If a client jump is implemented in the servlet file,
Response.sendredirect ("b.jsp");

Two

Client jump and server-side jump, the difference on the path
1. If you are using relative paths, there is no difference.
2. If the absolute path/start is used.
The client jump/start "/" represents the WebApp deployment to the WebApps directory on the Tomcat server
Server-side jump/Start, "/" represents the current project at the time of WebApp development.
Like what:
Response.sendredirect ("/bookmag/test.jsp"); (/= WebApps directory)
Request.getrequestdispater ("/test.jsp"). Forward (request,response); (/indicates current project)

Hit the code of the Little squirrel: <the end>

Common built-in objects in JSP (5) Small summary and two kinds of page jump mode (server-side switch, client jump) difference

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.