(1) Introduction to built-in objects
JSP provides some internal objects to simplify page development. These internal objects do not need to be instantiated by JSP writers. They are implemented and managed by containers on all JSP pages.
Internal objects can be used. All hidden objects are only useful for scriptlet or expressions and are not available in JSP declarations.
1. Out
The out object is encapsulated into the javax. servlet. jsp. jspwriter interface, which indicates the output stream opened by the customer. printwriter uses it to send the output stream to the client.
Used to output data to the client.
Out. println (object), out. Print (object) Output object type. The println method adds an empty row after the content, but the empty row is parsed by the browser.
To wrap a line, add out. println ("<br> ").
Out. newline () Outputs a newline character.
Out. Flush () outputs the data in the buffer.
Out. Close () Close the output stream.
Out. clearbuffer () clears the data in the buffer and outputs the data to the client.
Out. Clear () clears the data in the buffer, but does not output the data to the client.
Out. getbuffersize () obtains the buffer size.
Out. getremaining () obtains the size of the space not occupied in the buffer.
Out. isautoflush () returns a Boolean value.
2. Request
The request object represents the request object, which is encapsulated into the httpservletrequest interface. The request parameters can be obtained through the getparameter method, through get, post, head
You can obtain the request type by using methods such as cookies and referer.
Requests from the client are encapsulated by the request object after being processed by the servlet container. As a parameter of the jspservice () method, the request object is passed to the JSP page by the container.
Getattributenames () returns the name set of all attributes of the request object. The result is an enumeration type.
Getattribute (string name) returns the property value specified by name. If no value exists, null is returned.
Isuserinrole (string role) determines whether the authenticated user is a member of the logical role.
Getcookies () return all cookie objects on the client. The result is a cookie array.
Getcharacterencoding () returns the character encoding method in the request.
Getcontentlength () returns the length of the Request body. If the length is not determined,-1 is returned.
Getheader (string name) obtains the header information defined by the HTTP protocol.
Getheaders (string name) returns all the values of the request header with the specified name. The result is an enumeration type.
Getheadernames () returns the names of all request headers. enumeration.
Getinputstream () returns the input stream of the request to obtain data in the request.
Getmethod () is used to obtain data transmitted from the client to the server, such as post, get, header, and trace.
Getparameter (string name) obtains the parameter value sent from the client to the server. This parameter is specified by name, usually a parameter in the form.
Getparameternames () obtains the names of all parameters sent from the client to the server.
Getparametervalues (string name) obtains all values of the specified parameter, which is specified by name.
Getprotocol () gets the protocol name that the client uses to transmit data to the server.
Getquerystring () to obtain the query string, which is sent to the server by the client using the get method.
Getrequesturi () obtains the client address of the request string.
Getremoteaddr () obtains the IP address of the client.
Getremotehost () obtains the client name.
Getsession ([Boolean create]) returns the request-related session. When the create parameter is used and the parameter is true, if the client has not created a session, a new session will be created.
Getservername () gets the name of the server.
Getserverpath () obtains the file path of the script file requested by the client.
Getserverport () gets the server port number.
Removeattribute (string name) deletes an attribute in the request.
Setattribute (string name, java. Lang. ojbect objt) sets the value of the request parameter named name.
3. Response
Response is encapsulated into the httpservletresponse interface. It encapsulates the responses generated by JSP and is then sent to the client to respond to the customer's request. It is the same as the request object,
It is generated by the container and passed into the JSP as a parameter of the jspservice () method. Because the output stream is buffered, you can set the HTTP status code and response header.
Addcookie (cookie cook) adds a cookie object to save the user information of the client.
Addheader (string name, string value) adds HTTP file header information, which will be uploaded to the client. If a header with the same name already exists, it will overwrite the previous header.
Containsheader (string name) checks whether the specified Http File Header already exists, and then returns Boolean.
Encodeurl () uses sessionid to encapsulate the URL.
Flushbuffer () forces the content of the current buffer to be sent to the client.
Getbuffersize () returns the buffer size.
Getoutputstream () returns the output stream object to the client.
Senderror (INT) sends an error message to the client. For example, 404 indicates that the webpage does not exist or the requested webpage is invalid.
Sendredirect (string location) sends the response to another location for processing.
Setcontenttype (string contenttype) sets the mimel type of the response.
Setheaders (string name, strng value) sets the value of the HTTP file header with the specified name. If this value already exists, the new value overwrites the original value.
4. Session
The Session object is used to save the information of each user to track the operation status of each user. The session information is saved in the container, and the session ID is saved in the cookie of the client.
The httpsession interface corresponds to the session.
Getattribute (string name) gets the attribute associated with the specified name.
In jsp1.0, this method is session. getvalue (string name ).
Getattributenames () returns each attribute object stored in the session object.
Getcreationtime () returns the time when the session was created.
GETID () This method returns a unique identifier. Each session ID is different.