Jsp built-in objects and jsp built-in objects

Source: Internet
Author: User

Jsp built-in objects and jsp built-in objects

1. request object

The request information of the client is encapsulated in the request object, so that the client can understand the customer's requirements and then respond. It is an instance of the HttpServletRequest class.

Object getAttribute (String name) returns the attribute value of the specified attribute.
Enumeration getAttributeNames () returns the Enumeration of all available attribute names
String getCharacterEncoding () returns the character encoding method
Int getContentLength () returns the length of the Request body (in bytes)
String getContentType () Get the MIME type of the Request body
ServletInputStream getInputStream () obtains the binary stream of a row in the Request body.
String getParameter (String name) returns the parameter value of the specified name parameter.
Enumeration getParameterNames () returns the Enumeration of available parameter names
String [] getParameterValues (String name) returns an array containing all values of the parameter name
String getProtocol () returns the protocol type and version number of the request.
String getScheme () returns the scheduler name used for the request, such as http. https and ftp.
String getServerName () returns the server host name that receives the request
Int getServerPort () returns the port number used by the server to accept this request.
BufferedReader getReader () returns the decoded Request body.
String getRemoteAddr () returns the IP address of the client sending this request.
String getRemoteHost () returns the client host name that sends this request
Void setAttribute (String key, Object obj)
String getRealPath (String path) returns the actual path of a virtual path.

2. response object

The response object contains information about the response to the customer request, but it is rarely used directly in JSP. It is an instance of the HttpServletResponse class.


String getCharacterEncoding () character encoding used to return the response
ServletOutputStream getOutputStream () returns a binary output stream of the response.
PrintWriter getWriter () returns an object that can output characters to the client.
Void setContentLength (int len) set the Response Header Length
Void setContentType (String type) sets the MIME type of the response
SendRedirect (java. lang. String location) Redirects client requests


3. session Object

A session object refers to a session between the client and the server, starting from a WebApplication that the client connects to the server until the client and the server are disconnected. It is an instance of the HttpSession class.


Long getCreationTime () returns the SESSION Creation Time
Public String getId () returns the unique ID number set for the JSP Engine when the SESSION is created.
Long getLastAccessedTime () returns the last client request time in this SESSION
Int getMaxInactiveInterval () returns the interval between two requests this SESSION is canceled (MS)
String [] getValueNames () returns an array containing all available attributes of this SESSION.
Void invalidate () cancels the SESSION to make the SESSION unavailable
Boolean isNew () returns a SESSION created by the server, whether the client has been added
Void removeValue (String name) deletes the attribute specified in the SESSION.
Void setMaxInactiveInterval () sets the interval between two requests this SESSION is canceled (MS)

4. out object

An out object is an instance of the JspWriter class and is a common object for outputting content to the client.


Void clear () clears the buffer content
Void clearBuffer () clears the current content of the buffer
Void flush () clears the stream
Int getBufferSize () returns the size of the buffer in bytes. If no buffer is set, the value is 0.
Int getRemaining () returns how much available the buffer is.
Boolean isAutoFlush () indicates whether to automatically clear or throw an exception when the returned buffer is full.
Void close () to close the output stream

5. page Object

The page Object points to the current JSP page itself, a bit like the this pointer in the class. It is an instance of the java. lang. Object Class.


Class getClass returns the class of this Object
Int hashCode () returns the hash code of this Object
Boolean equals (Object obj) determines whether the Object is equal to the specified Object
Void copy (Object obj) copies the Object to the specified Object.
Object clone () clone this Object
String toString () converts the Object to a String Object.
Void y () Wake up a waiting thread
Void policyall () Wake up all waiting threads
Void wait (int timeout) enables a thread to wait until the timeout ends or is awakened.
Void wait () enables a thread to wait until it is awakened.
Void enterMonitor () locks the Object
Void exitMonitor () locks the Object

6. application Object

The application Object shares data between users and stores global variables. It starts from the start of the server until the server is closed. During this period, this object will always exist. In this way, the object can be connected between users or between users, you can perform operations on the same attribute of this object. Operations on this object attribute anywhere will affect access by other users. The startup and shutdown of the server determine the life of the application object. It is an instance of the ServletContext class.


Object getAttribute (String name) returns the attribute value to the name
Enumeration getAttributeNames () returns the Enumeration of all available attribute names
Void setAttribute (String name, Object obj)
Void removeAttribute (String name) deletes a property and its attribute values.
String getServerInfo () returns the JSP (SERVLET) engine name and version number.
String getRealPath (String path) returns the actual path of a virtual path.
ServletContext getContext (String uripath) returns the application Object of the specified WebApplication.
Int getMajorVersion () returns the maximum Servlet API version supported by the server.
Int getMinorVersion () returns the maximum Servlet API version supported by the server.
String getMimeType (String file) returns the MIME type of the specified file
URL getResource (String path) returns the URL path of the specified resource (file and directory ).
InputStream getResourceAsStream (String path) returns the input stream of the specified resource
RequestDispatcher getRequestDispatcher (String uripath) returns the RequestDispatcher object of the specified resource.
Servlet getServlet (String name) returns the Servlet with the specified name
Enumeration getServlets () returns the Enumeration of all servlets
Enumeration getServletNames () returns the Enumeration of all Servlet names
Void log (String msg) writes the specified message to the Servlet log File
Void log (Exception exception, String msg) writes the stack track and error message of the specified Exception to the Servlet log File
Void log (String msg, Throwable throwable) writes stack tracing and Throwable exception descriptions to the Servlet log file.

7. exception object

An exception object is an exception object. When an exception occurs during a page running, this object is generated. To apply this object to a JSP page, you must set isErrorPage to true; otherwise, compilation fails. It is actually a java. lang. Throwable object.


String getMessage () returns a message describing an exception.
String toString () returns a brief description message about the exception.
Void printStackTrace () displays exceptions and stack traces
Throwable FillInStackTrace () overwrites the execution stack track of an exception

8. pageContext object

The pageContext object provides access to all the objects and namespaces on the JSP page, that is, it can access the SESSION on this page, or take a property value of the application on this page, it is equivalent to the aggregator of all functions on the page. Its Class Name is also called pageContext.


JspWriter getOut () returns the JspWriter stream (out) in use in the current client response)
HttpSession getSession () returns the HttpSession object (session) on the current page)
Object getPage () returns the Object (page) of the current page)
ServletRequest getRequest () returns the ServletRequest object (request) of the current page)
ServletResponse getResponse () returns the ServletResponse object (response) of the current page)
Exception getException () returns the Exception object (exception) of the current page)
ServletConfig getServletConfig () returns the ServletConfig object (config) of the current page)
ServletContext getServletContext () returns the ServletContext object (application) of the current page)
Void setAttribute (String name, Object attribute) set attributes and attribute values
Void setAttribute (String name, Object obj, int scope) set attributes and attribute values within the specified range
Public Object getAttribute (String name) gets the attribute value
Object getAttribute (String name, int scope) obtains the attribute value within the specified range
Public Object findAttribute (String name) searches for an attribute and returns the starting attribute value or NULL.
Void removeAttribute (String name) deletes an attribute.
Void removeAttribute (String name, int scope) deletes an attribute within a specified range.
Int getAttributeScope (String name) returns the scope of an attribute.
Enumeration getAttributeNamesInScope (int scope) returns an Enumeration of available attribute names within a specified range.
Void release () releases resources occupied by pageContext
Void forward (String relativeUrlPath) causes the current page to be re-exported to another page
Void include (String relativeUrlPath) contains another file at the current position

9. config object

The config object is used by the JSP Engine to transmit information to a Servlet during initialization. This information includes the parameters used during Servlet initialization (consisting of attribute names and attribute values) and server-related information (by passing a ServletContext object)


ServletContext getServletContext () returns the ServletContext object containing server-related information.
String getInitParameter (String name) returns the value of the initialization parameter.
Enumeration getInitParameterNames () returns the Enumeration of all parameters required for Servlet initialization.


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.