JSP built-in object

Source: Internet
Author: User
ArticleDirectory
    • I. Request object:
I. Request object:

This object encapsulates the information submitted by the user. You can call the corresponding method of this object to obtain the encapsulated information, that is, you can use this object to obtain the information submitted by the user. It is an instance of httpservletrequest.

JSP

The following describes common request methods: 1, getparameter (); Use the following string STR = request. getparameter (); 2, setattribute (); and getattribute (); removeattribute (); getmethod (); getprotocol (); getreqeusturi (); getremoteaddr (); getserverport (); and getservername ();

Ii. Response object:

Send data to the client in a dynamic response to the customer's request.

Iii. Session Object

1. What is session: the session object is a JSP built-in object, which is automatically created when the first JSP page is loaded to complete session management. A session starts when a client opens a browser and connects to the server, and ends when the client closes the browser and leaves the server. When a customer accesses a server, it may connect several pages of the server and refresh a page repeatedly. The server should know in some way that this is the same customer, this requires the session object. 2. session Object ID: when a customer visits a JSP page on the server for the first time, the JSP engine generates a session object and assigns a string-type ID, the JSP engine sends this ID number to the client and stores it in the cookie, so that the session object and the customer have a one-to-one correspondence relationship. When the customer accesses other pages connected to the server, it will not allocate new session objects to the customer until the client closes the browser, and the session objects of the client on the server will be canceled, and the relationship with the customer's session disappears. When the client re-opens the browser and connects to the server, the server creates a new session object for the client. 3. The session object has a certain expiration time, so the name-value pairs in the session will be lost after a certain period of time. You can change the session validity time to avoid this situation. At the same time, when programming, try to avoid storing a large amount of valid information in the session, and request is a good alternative object.

4. Application Object

1. what is application: This application object is generated after the server is started. When the client browses between the pages of the accessed website, the application object is the same until the server is closed. However, unlike session, all customers share the same application object. 2. common Methods for application objects: (1) Public void setattribute (string key, object OBJ): add the object OBJ specified by the parameter object to the application object, specify an index keyword for the added object. (2) Public object getattribute (string key): obtains the object containing keywords in the Application object.

V. Out object

An out object is an output stream used to output data to the client. The out object is used to output various types of data.

6. page Java. Lang. Object

Corresponds to the this keyword. JSP page itself, the page object is an instance of the servlet class after the current page is converted. From the converted servlet classCodeObject page = this; in JSP pages, page objects are rarely used.

VII. config

Jav

JSP validator errors

[1]

An instance of ax. servlet. servletconfig, which represents the configuration information of the JSP. Common methods include getinitparameter (string paramnarne) and getinitparameternarnes. In fact, JSP pages do not need to be configured, so there is no configuration information. Therefore, this object is more effective in servlet.

8. Exception

Java. Lang. throwable instance, which represents exceptions and errors on other pages. This object can be used only when the iserrorpage attribute of the compiled command page is true. Common methods include getmessage () and printstacktrace.

9. pagecontext

Javax. servlet. jsp. pagecontext instance. This object represents the context of the JSP page and can be used to access Shared data on the page. Common methods include getservletcontext () and getservletconfig. // Use pagecontext to set the property, which is within the page range by default. setattribute ("page", "hello"); // you can use request to set the property. The property is within the request range by default. setattribute ("request", "hello"); // use pagecontext to set the property to pagecontext in the request range. setattribute ("request2", "hello", pagecontext. request_scope); // use session to set the attribute to the session range. setattribute ("session", "hello"); // use pagecontext to set the attribute to pagecontext within the session range. setattribute ("session2", "hello", pagecontext. session_scope); // use application to set attributes in the application range. setattribute ("app", "hello"); // use pagecontext to set the property to pagecontext within the application range. setattribute ("app2", "hello", pagecontext. appl job cation_scope );

 

 

JSP 2.0 Introduction

The new JSP specification version includes the new version for upgradingProgramThe efficiency functions of employees include:

JSP

An expression language (EL)Allows developers to Create Velocity-style templates (among other things). It is faster and easier to create new labels. Hello, $ {Param. Visitor} <% -- same as: Hello, <% = request. getparameter ("visitor") %> -- %>

MVC ModeTo separate the presentation layer presentation from the request processing and data storage, sun recommends a "Model-View-controller" Model-View-controller mode in JSP files. The standard servlet or separated JSP file is used to process requests. After the request is processed, the control is handed over to a JSP page that is only used to create the output. Several platforms are based on the module-View-control mode (such as Struts and Spring framework) at the network layer ).

 

 

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.