JSP built-in 9 object learning Summary (1)

Source: Internet
Author: User

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>
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.