Built-in objects for JSPs

Source: Internet
Author: User

1.request objects

The client's request information is encapsulated in the requests object to understand the customer's needs and respond. It is an instance of the HttpServletRequest class.

Object GetAttribute (String name) returns the property value of the specified property
Enumeration Getattributenames () returns an enumeration of all available property names
String getcharacterencoding () returns the character encoding method
int Getcontentlength () returns the length of the request body (in bytes)
String getContentType () Gets the MIME type of the request body
ServletInputStream getInputStream () gets the binary stream of a row in the request body
String GetParameter (string name) returns the parameter value of name specified parameter
Enumeration Getparameternames () returns an enumeration of the available parameter names
String[] Getparametervalues (String name) returns an array of all values that contain the parameter name
String Getprotocol () returns the protocol type and version number of the request
String Getscheme () returns the requested plan name, such as: Http.https and FTP
String getServerName () returns the host name of the server that accepts 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 that sent this request
String Getremotehost () returns the host name of the client that sent this request
void SetAttribute (String key,object obj) to set property values for a property
String Getrealpath (string path) returns the true path of a virtual path

2.response objects

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.


String getcharacterencoding () returns what character encoding is used for 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) to set the response header length
void setContentType (String type) sets the MIME type of the response
Sendredirect (java.lang.String location) REDIRECT client request


3.session objects

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


Long GetCreationTime () returns session creation time
Public String GetId () returns the unique ID number that the JSP engine sets for the session when it is created
Long Getlastaccessedtime () returns the client's last request time in this session
int Getmaxinactiveinterval () returns the two request interval how long this session was canceled (MS)
String[] GetValueNames () returns an array containing all the properties available in this session
void Invalidate () cancels session, making session unavailable
Boolean isnew () returns a session created by the server, whether the client has joined
void RemoveValue (String name) deletes the property specified in the session
void Setmaxinactiveinterval () sets the two request interval for how long this session is canceled (MS)

4.out objects

An Out object is an instance of the JspWriter class and is an object commonly used to output content to the client


void Clear () clears the contents of the buffer
void Clearbuffer () clears the current contents of the buffer
void flush () empty stream
int GetBufferSize () returns the buffer as the size of the number of bytes, if no buffer is set to 0
int getremaining () returns how much of the buffer is remaining available
Boolean Isautoflush () returns whether the buffer is full, automatically emptied or throws an exception
void Close () to close the output stream

5.page objects

The Page object is pointing to the current JSP page itself, a bit like the this pointer in the class, which is an instance of the Java.lang.Object class


Class GetClass Returns the classes of this object
int Hashcode () returns the hash code of this object
Boolean equals (Object obj) to determine whether this object is equal to the specified object
void copy (object obj) copies this object to the specified object
Object Clone () clones this object
String toString () converts the object object to a String class
void Notify () wakes up a waiting thread
void Notifyall () Wakes all waiting threads
void Wait (int timeout) causes a thread to wait until timeout ends or is awakened
void Wait () causes a thread to wait until it wakes up
void Entermonitor () lock on object
void Exitmonitor () to unlock object

6.application objects

The Application object implements the sharing of data among users and can store 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 on the user's back-and-forth connection or in a connection between different users, and the operation of this object property anywhere will affect access to it by other users. The startup and shutdown of the server determines the life of the Application object . It is an instance of the ServletContext class.


Object getattribute (String name) returns the property value for the given name
Enumeration Getattributenames () returns an enumeration of all available property names
void SetAttribute (String name,object obj) sets the property value of the property
void RemoveAttribute (String name) deletes an attribute and its property value
String Getserverinfo () returns the JSP (SERVLET) engine name and version number
String Getrealpath (string path) returns the true path of a virtual path
ServletContext getcontext (String uripath) returns the Application object for the specified WebApplication
int Getmajorversion () returns the maximum version number of the Servlet API supported by the server
int Getminorversion () returns the maximum version number of the Servlet API supported by the server
String GetMimeType (String file) returns the MIME type of the specified file
URL getresource (String path) returns the URL path for the specified resource (file and directory)
InputStream getResourceAsStream (String path) returns the input stream for the specified resource
RequestDispatcher Getrequestdispatcher (String uripath) returns the RequestDispatcher object for the specified resource
Servlet getservlet (String name) returns the servlet of the specified name
Enumeration Getservlets () returns an enumeration of all Servlets
Enumeration Getservletnames () returns an enumeration of all servlet names
void log (String msg) writes the specified message to the servlet's log file
void log (Exception exception,string msg) writes the stack trace and error message of the specified exception to the servlet's log file
void log (String msg,throwable throwable) writes the description information of the stack trajectory and the given Throwable exception to the servlet's log file

7.exception objects

The exception object is an exception object that is created when a page has an exception during the run. If a JSP page is to be applied to this object, the Iserrorpage must be set to true, otherwise it cannot be compiled. He's actually a java.lang.Throwable object.


String GetMessage () returns a message describing the exception
String toString () returns a short description message about the exception
void Printstacktrace () shows exceptions and their stack traces
Throwable Fillinstacktrace () overriding the execution stack trajectory of the exception

8.pageContext objects

The PageContext object provides access to all objects and namespaces within the JSP page, which means that he can access the session where the page is located, or a property value of the application that is located on the pages, which is the equivalent of all the functions in the page. The class name is also called PageContext.


JspWriter getout () returns the current client response used by the JspWriter stream (out)
HttpSession getsession () returns the HttpSession object (session) in the current page
Object GetPage () returns the current page of Object Objects (page)
ServletRequest getrequest () returns the ServletRequest object of the current page (request)
Servletresponse GetResponse () returns the Servletresponse object of the current page (response)
Exception getexception () returns the Exception object of the current page (Exception)
ServletConfig Getservletconfig () returns the ServletConfig object (config) of the current page
ServletContext Getservletcontext () returns the ServletContext object of the current page (application)
void SetAttribute (String name,object attribute) setting properties and property values
void SetAttribute (String name,object obj,int scope) sets properties and property values within a specified range
Public Object getattribute (String name) takes the value of the property
Object getattribute (String name,int scope) takes the value of the property within the specified range
Public Object Findattribute (String name) looks for a property that returns the property value or null
void RemoveAttribute (String name) Deletes a property
void RemoveAttribute (String name,int scope) Deletes a property at the specified range
int Getattributescope (String name) returns the scope of an attribute
Enumeration Getattributenamesinscope (int scope) Returns the property name enumeration available within the specified range
void release () frees resources occupied by PageContext
void forward (String Relativeurlpath) redirects the current page to another page
void include (String relativeurlpath) 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 the parameters to be used when the servlet initializes (through property names and property values) and information about the server (by passing a ServletContext object)


ServletContext Getservletcontext () returns ServletContext object containing information about the server
String Getinitparameter (string name) returns the value of the initialization parameter
Enumeration Getinitparameternames () returns an enumeration of all parameters required by the servlet initialization


Built-in objects for JSPs

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.