JSP Common 9 large built-in objects

Source: Internet
Author: User

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ||||||||
one, built-in object type scope :
Request Javax.servlet.http.HttpServletRequest Request
Response Javax.servlet.http.HttpServletResponse Response
PageContext Javax.servlet.jsp.PageContext Page
Session Javax.servlet.http.HtpSession Session
Application Javax.servlet.jsp.ServletContext Application
Out Javax.servlet.jsp.JspWriter page
Config Javax.servlet.ServletConfig page
Page Java.lang.Object page
Exception java.lang.Throwable Page
second, the scope of the object :

1, page: Is the set of properties can only be valid on the current page. Through PageContext's setattribute () and getattribute ().
2. Request: The attribute is valid within the scope of a request. If the page jumps from one page to another, the property is invalidated
The The jump referred to here refers to a client jump, such as a customer clicking a hyperlink to jump to another page or browsing through the browser's address bar for other
Page. If the server-side jump <jsp:forward> is used, the property remains in effect. Similarly, use the setattribute () and getattribute () of the Request object.
3, session: Refers to the client browser and server a session within the scope, if the server disconnects, then the attribute is invalid. By the same token
The setattribute () and getattribute () of the Session object. Exceptions to session scope such as reopening a browser.
4, Application: Refers to the entire server scope, know that the server will not expire after the failure. Similarly, through the Seta of application objects
Ttribute () and getattribute (). The application range is the saved property that can be obtained on any page without restarting the server.
You can get properties even if you reopen the browser.

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||

1.request objects
Client requests are encapsulated in the request object to be able to understand the customer's needs,
and then respond. It is an instance of the HttpServletRequest class.

1.objectgetAttribute (Stringname) Returns the property value of the specified property
2.EnumerationgetAttributeNames () returns an enumeration of all available property names
3. Stringgetcharacterencoding () returns the character encoding
4.intgetContentLength () returns the length of the request body (in bytes)
5.StringgetContentType () Gets the MIME type of the request Body
6.ServletInputStreamgetInputStream () gets the binary stream of a row in the request Body
7.EnumerationgetParameterNames () Returns an enumeration of the available parameter names
8.string[]getparametervalues (stringname) returns an array of all values that contain the parameter name
9.StringgetProtocol () returns the protocol type and version number of the request
10.intgetServerPort () returns the port number used by the server to accept this request
11.voidsetAttribute (stringkey,objectobj) Setting property value for property
-------------------------------------------------------------------------------------------------------------- -----------
2.response object
The Response object contains information about the response to a customer request, but it is seldom used directly in the JSP.
It is an instance of the HttpServletResponse class.

1.StringgetCharacterEncoding () returns a binary output stream
3 that responds with what character encoding
2.ServletOutputStreamgetOutputStream () returns the response. Printwritergetwriter () Returns an object that can output characters to the client
4.voidsetContentLength (Intlen) to set the response header length
5.voidsetContentType ( StringType) Sets the MIME type of the response
6.sendRedirect (java.lang.Stringlocation) REDIRECT client request

3.session object
The session object refers to the client-to-server conversation, starting with the client connecting to a
WebApplication on the server until the client disconnects from the server. It is an instance of the HttpSession
class.

1.longgetCreationTime () returns session creation time
2.publicStringgetId () returns the unique ID number that the JSP engine set for the session when it was created
3. Longgetlastaccessedtime () returns the last request time of the client in this session
4.intgetMaxInactiveInterval () returns the two request interval how long this session was canceled (MS)
5.string[]getvaluenames () returns an array containing all the properties available in this session
6.voidinvalidate () to cancel the session so that the session is not available
7. Booleanisnew () returns a session created by the server, whether the client has joined
8.voidremoveValue (stringname) to delete the attribute specified in session
-------------------------------------------------------------------------------------------------------------- -----------
4.out object
An Out object is an instance of the JspWriter class and is an object that is commonly used to output content to the client

1.voidclear () clears the contents of the buffer
2.voidclearBuffer () clears the current contents of the buffer
3.voidflush () empty stream
4.intgetBufferSize () Returns the buffer as the size of the number of bytes, if no buffer is set to 0
5.intgetRemaining () returns how much of the buffer remains available
6.booleanisAutoFlush () returns the buffer full, whether it is automatically emptied or throws an exception
7. Voidclose () close the output stream
------------------------------------------------------------ -------------------------------------------------------------
5.page Object
Page object is a pointer to the current JSP page itself, a bit like this in the class, which is an instance of the
Java.lang.Object class

1.classgetClass returns the class of this object
2.inthashCode () returns the hash code for this object
3.booleanequals (objectobj) Determines whether this object is equal to the specified Object object
4.voidcopy (objectobj) copies this object to the specified object object
5.Objectclone () to clone the object
6. Stringtostring () Converts this object object to a String class
7.voidnotify () wakes up a waiting thread
8.voidnotifyAll () wakes up all waiting threads
9.voidwait (inttimeout) causes a thread to wait until timeout ends or is awakened
10.voidwait () causes a thread to wait until it wakes up
11.voidenterMonitor () to object locking
12. Voidexitmonitor () Unlocks object
-------------------------------------------------- -----------------------------------------------------------------------
6.application object
The Application object implements the sharing of data between users, which can hold global variables. It starts at the start of the server
until the server shuts down, during which time this object will persist, so that the same properties of the object can be manipulated in the connection between the user's front
or a different user, and at any
place on the property of this object. Will affect the access of other users to this. The startup and
shutdown of the server determine the life of the Application object. It is an instance of the ServletContext class.

1.ObjectgetAttribute (Stringname) returns the property value for the given name
2.EnumerationgetAttributeNames () Returns an enumeration of all available property names
3.voidsetAttribute (stringname,objectobj) Setting property values for a property
4.voidremoveAttribute (stringname) Delete an attribute and its property value
5.StringgetServerInfo () returns the JSP (SERVLET) engine name and version number
6.StringgetRealPath (Stringpath) returns the true path of a virtual path
7.ServletContextgetContext (Stringuripath) returns the Application object for the specified WebApplication
8.StringgetMimeType (Stringfile) returns the MIME type of the specified file
9.URLgetResource (Stringpath) returns the URL path for the specified resource (file and directory)
10.InputStreamgetResourceAsStream (Stringpath) returns the input stream for the specified resource
11.RequestDispatchergetRequestDispatcher (Stringuripath) returns the RequestDispatcher object for the specified resource
12.ServletgetServlet (Stringname) returns the servlet of the specified name
13.EnumerationgetServlets () Returns an enumeration of all Servlets
14.EnumerationgetServletNames () Returns an enumeration of all servlet names

--------------------------------------------------------------------------------------------------------------- ----------

7.exception objects
The exception object is an exception, and when an exception occurs during a page run
The object of the birth. If a JSP page is to be applied to this object, the Iserrorpage must be set to True,
1.StringgetMessage () returns a message describing the exception
2.StringtoString () returns a short description message about the exception
3.voidprintStackTrace () display exceptions and their stack traces
4.ThrowableFillInStackTrace () Rewrite the exception's execution stack trajectory
----------------------------------------------------------------------------------------------------------- --------------
8.pageContext Objects
The PageContext object provides access to all objects and namespaces within the JSP page, i.e.
Says he can access the session where this page is located, or you can take the application
A property value, which is equivalent to the synthesizer of all the functions in the page, and the name of the class is also called PageContext.

1.JspWritergetOut () returns the JspWriter stream (out) of the current client response being used
2.HttpSessiongetSession () returns the HttpSession object (session) in the current page
3.ObjectgetPage () Return object object of the current page (page)
4.ServletRequestgetRequest () returns the ServletRequest object of the current page (request)
5.ServletResponsegetResponse () returns the Servletresponse object of the current page (response)
6.ExceptiongetException () Returns the exception object of the current page (exception)
7.ServletConfiggetServletConfig () returns the ServletConfig object (config) of the current page
8.ServletContextgetServletContext () returns the ServletContext object of the current page (application)
9.voidsetAttribute (Stringname,objectattribute) Setting properties and property values
10.voidsetAttribute (Stringname,objectobj,intscope) Set properties and property values within a specified range
11.publicObjectgetAttribute (Stringname) Take the value of the property
12.ObjectgetAttribute (Stringname,intscope) takes the value of a property within a specified range
13.publicObjectfindAttribute (Stringname) Looking for a property that returns a property value or null
14.voidremoveAttribute (Stringname) Delete a property
15.voidremoveAttribute (Stringname,intscope) Deletes a property in the specified range
16.intgetAttributeScope (Stringname) returns the scope of a property
17.EnumerationgetAttributeNamesInScope (Intscope) Returns the property name enumeration available within the specified range
18.voidrelease () frees up resources occupied by PageContext
19.voidforward (Stringrelativeurlpath) redirects the current page to another page
20.voidinclude (Stringrelativeurlpath) contains another file at the current location
----------------------------------------------------------------------------------------------------------- --------------
9.config Objects
The Config object is used by the JSP engine to pass information to it when a servlet is initialized, including when the servlet initializes
Parameters (consisting of property names and property values) and information about the server (by passing a ServletContext object)

JSP Common 9 large built-in objects

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.