JSP has nine built-in objects: request, response, session, application, out, pagecontext, config, page, and exception. These objects are implemented and managed by system containers and can be directly used on the JSP page without being defined.
I. The request object is javax. servlet. HTTP. httpservletrequest type object, which represents the request information of the client, it is mainly used to receive data (including header information, system information, request method, and request parameters) transmitted to the server over HTTP ). The scope of the request object is one request. 1. Obtain the request parameter value <body> <a href = "text. jsp? Id = 007 & name = TT "> obtain the value of the Request Parameter </a> </body>. You can use the following method to obtain the string id = request. getparameter ("ID"); string name = request. getparameter ("name"); 2. solve Chinese garbled characters. If the input parameter contains Chinese characters, for example, <body> <a href = "text. JSP? Id = 007 & name = Tao "> GET request parameter value </a> </body> what we get will be garbled, all request requests are iso-8859-1 encoded, we can use GBK, gb2312, UTF-8 and Other encoding. Solution: String id = new string (request. getparameter ("ID "). getbytes ("iso-8859-1"), "GBK"); string name = request. getparameter ("name"); 3. the methods for obtaining Form submission data to obtain Form submission data are basically the same as those for obtaining request parameters, except that the object value is obtained by name. On the HTML page, A group of data can have the same name, that is, the same name can correspond to multiple data, so we need to use request. getparameter (name); Request. getparametervalues (name); two methods to obtain data. 4. obtain the request client information <HTML> By using the void setattribute (string name, object O) method, you can add an attribute in the attribute column of the request object and obtain the value of the corresponding attribute through the object getattribute (string name) method, you can remove this attribute using the void removeattribute (string name) method. (I do not know how to use it for the moment ?)
6. Cookie Management
Creates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management.
Constructor Summary
:
Cookie
(String name, String value)
You can use the getcookie () method of cookie to obtain the set of all cookie objects. Then, you can use the getname () method of the cookie object to obtain the cookie with the specified name, and then use getvalue () you can obtain the value of the cookie object and send a cookie object to the client using the addcookie () method of the response object. For example, if a simple user login page login. jsp is submitted to the show. jsp page, we can use cookies to save user information.
Login. jsp<HTML> Show. jsp<HTML>