Take a look at the request response pattern of the Web application before you learn the nine built-in objects.
Web Application Request Response Mode
The request response pattern for the Web application is illustrated:
1) Users send requests (request)
2) server response to User (response)
Life case:
JSP nine large built-in objects list
JSP built-in objects are Java objects that the Web container provides for each page, and developers can use them directly without explicitly declaring them without using
The New keyword is a built-in object that you can use. JSP built-in objects are also referred to as predefined variables.
The nine main built-in objects are:
A brief introduction to the nine built-in objects is shown in the following table:
Out Object
An Out object is an instance of the Javax.servlet.jsp.JspWriter class that is used to write content to the response object, which is more commonly used to output content to the client
The object.
The Out object is used to output information within a Web browser and to manage the output buffers on the application server. When you use an Out object to output data, you can
The data buffer is manipulated, the residual data in the buffer is purged in time, and the buffer space is conceded for the other output. When the data output is complete, you must promptly close
The output stream is closed.
The original JspWriter class objects perform different instantiation operations based on whether the page has a cache. Can be used in the page directive
Buffered= ' false ' property to easily close the cache.
The JspWriter class contains the methods in most of the Java.io.PrintWriter classes. However, JspWriter has added a number of new designs specifically designed to handle caching.
Square law. Also, the JspWriter class throws ioexceptions exceptions, and PrintWriter does not.
Common methods for out objects are as follows:
Let's look at a specific example:
We use some of the above out object methods to output a tang poem and the code about the buffer information:
Output Result:
Add the Flush () method after two sentences in the code above to see if there is a difference:
Output Result:
In terms of the remaining size of the buffer from the output, the number of bytes remaining in the buffer becomes larger.
Calling the clear () method after using the flush () method throws an exception, causing the subsequent results to not be output. This is what we should try to avoid. We
In the code, try:
Operation Result:
Calling the Clearbuffer () method after using the flush () method does not throw an exception, and the subsequent result will still be the complete output.
Operation Result:
The flush () method is to first output the contents of the buffer and then clear the clear () method to clear the buffer directly.
Request Object
The Request object is an object of type Javax.servlet.httpServletRequest. This object represents the client's request information and is used primarily to accept
Data transmitted to the server via the HTTP protocol (including header information, System Information, request mode, request parameters, etc.). The request object is scoped to a
Request.
The client's request information is encapsulated in the requests object to understand the customer's needs and respond. The Request object has please
The object remains in effect until the client's request is completed. Whenever a client requests a JSP page, the JSP engine creates a new
Requests object to represent this request.
The Request object provides a series of methods to get the HTTP header information, the Cookies,http method, and so on.
Methods commonly used by the request object:
We need to know before we make an instance that there are two ways to submit a form: Get and post
The syntax format for expressing commits is:
<form name= "RegForm" action= "action" method= "Submission method" ></form>
Difference:
1) Get Submit method
Data is submitted in clear text through a URL, and the data is visible in the URL. The data submitted is not more than 2KB. Less security but more efficient
High Post mode. It is suitable for data with small amount of data and low security. For example: Search, Query and other functions.
Instance:
login.jsp page:
dologin.jsp page:
Operation Result:
2) Post Submission method
Encapsulates the user-submitted information within the HTML header. It is suitable for submitting user information with large data volume and high security performance, such as: registration, modification,
Upload and other functions.
Instance:
In the above Login.jsp page submission method to post:
The dologin.jsp page is still the same.
Enter the same user name and password to submit the results to the dologin.jsp page:
Look again at the instance of the Reuqest object
Let's use the request object to accept the submitted hobby options:
Reg.jsp page Code:
Request.jsp page Code:
Operation Result:
If we want to enter the user name in the Chinese user name, the above results will lead to garbled, we add a code on the request.jsp page:
Results of the last run:
So we use URLs to pass user names?
Add such a piece of code to the reg.jsp page:
Results of the last run:
Think again, then the URL is passed the Chinese user name? The above aspects can not solve the garbled, this time need to modify the Web. XML configuration file
Some of the parameters in:
In the Conf directory under the Tomcat Server installation directory, under the Server.xml connector Plus:
<connector port= "8080" protocol= "http/1.1" connectiontimeout= "20000" redirectport= "8443" URIEncoding= "UTF-8"/ >
Restart the Tomcat server.
The result of the last run is:
We can also add some user properties and their corresponding property values on the request.jsp page:
Results of the last run:
We use some of the methods of the request object to test and add code to the request.jsp page:
The result of the final operation:
Java Web Learning (one): JSP nine large built-in objects (i)