9 built-in objects for JSPs

Source: Internet
Author: User
Tags locale stack trace throwable unique id

9 Built-in objects

Built-in objects in a JSP (9)

Type range of object name object
PageContext Javax.servlet.jsp.PageContext Page
Page Javax.servlet.jsp.HttpJspPage page
Request Javasx.servlet.jsp.HttpServletRequest Request
Response Javax.servlet.jsp.HttpServletResponse Page
Session Javax.servlet.HttpSessio Session
Application Javax.servlet.ServletContext Application
Out Javax.servlet.jsp.JspWriter Page
Config Javax.servlet.ServletConfig Page
Exception Java.lang.ThrowAble Page

Built-in objects are objects that do not need to be declared and can be used directly in the JSP, and JSP has the following built-in objects:
1.request Objects
The request represents the HttpServletRequest object. It contains information about browser requests and provides several useful ways to get Cookie,header, and session data. The client's request information is encapsulated in the requests object to understand the customer's needs and respond.

1 Object getattribute (String name) returns the property value of the specified property, and returns null if the property does not exist.
2 enumeration Getattributenames () returns an enumeration of all available property names
3 String getauthtype (); Returns the name of the authentication method used to protect the servlet, and returns NULL when unprotected.
4 String getcharacterencoding () returns the character encoding method
5 int Getcontentlength () returns the length of the request body (in bytes) and returns-1 if the length is not determined.
6 String getContentType () Gets the MIME type of the request body
7 String Getcontentpath () returns the requested path.
8 cookie[] GetCookies () returns an array of all cookies for the client.
9 enumeration Getheadernames () returns a collection of the names of all HTTP headers.
Enumeration Getheaders (String name) returns a collection of all values for the specified HTTP header.
String GetHeader (string name) returns information for the HTTP header of the specified name.
A long Getdateheader (String name) returns the information for the HTTP header of the data type of the specified name.
The int getintheader (String name) returns the information for the HTTP header of type int of the specified name.
ServletInputStream getInputStream () gets the binary stream of a row in the request body
The locale GetLocale () returns the locale object for the current page, which can be set in response.
Enumeration Getlocales () returns a collection of all the locale objects in the request.
A String getlocalname () Gets the server-side host name of the response request.
String getlocaladdr () Gets the server-side address of the response request.
int Getlocalport () gets the server-side port of the response request
The String GetMethod () Gets the method (get, POST) that the client sends the request to the server side.
String GetParameter (string name) returns the parameter value of name specified parameter
Map Getparametermap () This method returns a Map object that contains all the parameters in the request.
Enumeration Getparameternames () returns a collection of all parameters in the request.
String[] Getparametervalues (String name) returns an array of all values that contain the parameter name
String getquerystring () returns the argument string passed by the Get method, which does not break out individual parameters.
The String getpathinfo () removes additional information from the request that is between Servletpath and QueryString.
String getpathtranslated () returns the actual path to the path information obtained with the GetPathInfo () method.
The String Getprotocol () returns the protocol used by the request. It could be HTTP1.1 or HTTP1.0.
BufferedReader Getreader () returns the reader object for the requested input stream, which can only be called in one page by the getInputStream () method.
String getremoteaddr () returns the IP address of the client sending this request
String Getremotehost () returns the host name of the client that sent this request
The String Getremoteuser () returns the client-authenticated user name without validation returning null.
The Getremoteport int () returns the client host port on which the request was made.
String Getrealpath (string path) returns the true path of a virtual path
RequestDispatcher getrequestdispatcher (String Path) generates resources for a given path to the processing adapter object.
The String Getrequestedsessionid () returns the identity of the requested session.
The PNS string RequestUri () returns the client address that made the request, but does not include the requested parameter string.
StringBuffer Getrequesturi () returns the server-side address of the response request
Getscheme String () returns the name of the plan used for the request, such as Http.https and FTP
The String getServerName () returns the name of the server in response to the request.
Getservletpath String () Gets the file path of the script file requested by the client.
Getserverport int () returns the port number used by the server to accept this request
A. void RemoveAttribute (String name) removes the property of the specified name in the property list.
A. void SetAttribute (String name, Object value) adds/removes the specified property in the property list.
A. void setcharacterencoding (String name) sets the requested character encoding format.
HttpSession getsession ();
HttpSession getsession (Boolean Create) gets the session, if Create is true, creates one without a session.
Boolean Isrequestedsessionidfromcookie () checks whether the requested session ID is passed through a cookie.
The. Boolean Isrequestedsessionidfromurl () checks whether the requested session ID is passed in through a URL.
A. Boolean isrequestedsessionidvalid () checks whether the requested session ID is still valid.
The Boolean issecure () checks if the request uses a secure link, such as HTTPS.
The. Boolean isuserinrole (String role) checks whether the user who has passed the validation is in role-specified roles.
Principal Getuserprincipal () returns a Java.security.Principal object that contains the user's login name.
Members:
String Basic_Auth = "BASIC"
String Client_cert_auth = "Client_cert"
String Digest_auth = "DIGEST"
String Form_auth = "FORM"

2.response ObjectsResponse
Represents the HttpServletResponse object, which mainly passes the result of the JSP container processing back to the client.

1 void Addcookie (cookie cookie) Adds a cookie object that holds client information.
2 void Adddateheader (String name, Long value) adds a date type of HTTP header information that overwrites HTTP header information with the same name.
3 void AddHeader (string name, string value) adds an HTTP header that overwrites the old HTTP header with the same name.
4 void Addintheader (String name, int value) adds an integer HTTP header that overwrites the old HTTP header with the same name.
5 Boolean Containsheader (String name) determines whether the specified HTTP header exists.
6 string encoderedirecturl (string url) encodes the URL used by the Sendredirect () method.
7 string encodeurl (string url) encodes the URL and callbacks the URL containing the SessionID.
8 void Flushbuffer () forces the contents of the current buffer to be sent to the client.
9 int getbuffersize () gets the buffer size in kilobytes.
The string getcharacterencoding () gets the character encoding format of the response.
One String getContentType () Gets the type of the response.
Locale GetLocale () Gets the locale object of the response.
Servletoutputstream Getoutputstream () returns the client's output stream object.
PrintWriter getwriter () gets the writer object corresponding to the output stream.
The Boolean iscommitted () determines whether the server has output data to the client.
void Reset () empties all contents in buffer.
The void Resetbuffer () condition contains all the contents of the buffer, but retains the HTTP header and status information.
void Senderror (int xc, String msg)
void Senderror (int xc) sends errors, including status codes and error messages.
The Sendredirect (String Locationg) sends the response to another location for processing.
void setbuffersize (int size) sets the buffer size in kilobytes.
A void setcharacterencoding (String charset) sets the character encoding format used by the response.
a void setcontentlength (int length) sets the body length of the response.
The type of the response is set at setContentType (String type).
Setdateheader (String name, Long value) sets the value of the HTTP header for the data type of the specified name.
void SetHeader (string name, string value) sets the value of the HTTP header for the specified name.
$ void Setintheader (String name, int value) sets the value of the HTTP header of type int of the specified name.
SetStatus (int XC) Sets the response status code, and the new value overrides the current value.
Member (HTTP status code):
int sc_continue = int Sc_switching_protocols =101
int SC_OK = sc_non_authoritative_information int =203
int sc_accepted = 202 int sc_created = 201
int sc_no_content = 204 int sc_reset_content =205
int sc_partial_content = 206 int sc_multiple_choices =300
int sc_moved_permanently = 301 int sc_moved_temporarily =302
int sc_found = 302 int sc_see_other = 303
int sc_not_modified = 304 int Sc_use_proxy =305
int sc_temporary_redirect = 307 int Sc_bad_request =400
int sc_unauthorized = 401 int sc_payment_required =402
int sc_forbidden = 403 int Sc_not_found =404
int sc_method_not_allowed = 405 intsc_not_acceptable

3.session Objects
The session represents a requested Javax.servlet.http.HttpSession object. Refers to a client-to-server session, starting with a webapplication from the client to the server until the client disconnects from the server.
1 long GetCreationTime () returns session creation time
2 public String GetId () returns the unique ID number that the JSP engine sets for the session when it is created
3 Long Getlastaccessedtime () returns the client's last request time in this session
4 int Getmaxinactiveinterval () returns 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 void Invalidate () Cancel session to make session unavailable
7 Boolean isnew () returns a session created by the server, whether the client has joined
8 void RemoveValue (String name) removes the attribute specified in session
9 void Setmaxinactiveinterval () set two request interval how long this session is canceled (MS)

4.out Objects
The Out object is an instance of Javax.jsp.JspWriter and provides several methods that you can use to echo the output to the browser.
1 void Clear () clears the contents of the buffer, but does not output to the client.
2 void Clearbuffer () clears the current contents of the buffer and outputs it to the client.
3 void Close () closes the output stream and clears all content.

4 void Flush () outputs the data inside the buffer.
5 int GetBufferSize () returns the buffer as the size of the number of bytes, or 0 if no buffer is set
6 int getremaining () returns how much of the buffer is remaining available
7 Boolean Isautoflush () returns when the buffer is full, automatically empties or throws an exception
8. void NewLine () outputs a newline character.
9. Void Print (Boolean b) outputs the specified type of data to the HTTP stream, without wrapping
void println (Boolean b) outputs data of the specified type to the HTTP stream, and outputs a newline character.
11.
Appendable append (char c)
Appendable Append (charsequence cxq, int start, int end)
Appendable Append (charsequence cxq)
Adds a character or object that implements the Charsequence interface to the back of the output stream.
Members:
int default_buffer = 0-Default buffer size
int no_buffer = -1-writer is in buffered output state
int unbounded_buffer = 2-whether to limit buffer size


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
1 class GetClass Returns the classes of this object
2 int hashcode () returns the hash code of this object
3 Boolean equals (Object obj) to determine whether this object is equal to the specified object objects
4 void Copy (object obj) copies this object to the specified object
5 Object Clone () to clone this object
6 string toString () converts this object to the object of the String class
7 void Notify () wakes up a waiting thread
8 void Notifyall () wakes up all waiting threads
9 void Wait (int timeout) causes a thread to wait until timeout ends or is awakened
Ten void Wait () causes a thread to wait until it wakes up
one void Entermonitor () lock on object
void Exitmonitor () to unlock object


6.application Objects
Applicaton represents a Javax.servlet.ServletContext object. He realizes the sharing of data between 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;

The same property of this object can be manipulated, and any manipulation of this object property anywhere will affect the other user's

Access. The startup and shutdown of the server determines the life of the Application object.

1 Object getattribute (String name) returns the property value for the given name
2 enumeration Getattributenames () returns an enumeration of all available property names
3 void SetAttribute (String name,object obj) sets the property value of the property
4 void RemoveAttribute (String name) deletes an attribute and its property value
5 String Getserverinfo () returns the JSP (SERVLET) engine name and version number
6 string Getrealpath (string path) returns the true path of a virtual path
7 ServletContext getcontext (String uripath) returns the Application object for the specified WebApplication
8 int Getmajorversion () returns the maximum version number of SERVLETAPI supported by the server
9 int getminorversion () returns the maximum version number of SERVLETAPI supported by the server
Ten string GetMimeType (string file) returns the MIME type of the specified file
One-by-one 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
Getservlet servlet (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
The Void log (String msg,throwable throwable) writes the description information of the stack trajectory and the given Throwable exception to the servlet's

Log files.

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 should be

With this object, the Iserrorpage must be set to true, otherwise it cannot be compiled. He is actually the object of java.lang.Throwable.

8.pageContext Objects
PageContext represents a Javax.servlet.jsp.PageContext object. The PageContext object provides all objects within the JSP page and

namespace access, which means that he can access the session where this page is located, or you can take a property value of the application



1 JspWriter getout () returns the current client response used by the JspWriter stream (out)
2 HttpSession getsession () returns the HttpSession object (session) in the current page
3 Object GetPage () returns the current page of Object Objects (page)
4 ServletRequest Getrequest () returns the ServletRequest object of the current page (request)
5 Servletresponse GetResponse () returns the Servletresponse object of the current page (response)
6 Exception GetException () returns the Exception object of the current page (Exception)
7 ServletConfig Getservletconfig () returns the ServletConfig object (config) of the current page
8 ServletContext Getservletcontext () returns the ServletContext object of the current page (application)
9 void SetAttribute (String name,object attribute) set properties and property values
void SetAttribute (String name,object obj,int scope) sets properties and property values within a specified range
One 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) to delete a property
void RemoveAttribute (String name,int scope) Deletes a property at the specified range
Getattributescope Int (String name) returns the scope of a property
Enumeration Getattributenamesinscope (int scope) Returns the property name enumeration available within the specified range
void release () releases the resources occupied by PageContext
Forward (String Relativeurlpath) to redirect the current page to another page
void include (String relativeurlpath) contains another file at the current location


9.config Objects
Config represents a Javax.servlet.ServletConfig object.
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.

(consisting of property names and property values) and information about the server by passing a ServletContext object. )

1 ServletContext getservletcontext () returns ServletContext object containing information about the server
2 string Getinitparameter (string name) returns the value of the initialization parameter
3 enumeration Getinitparameternames () returns an enumeration of all parameters required by the servlet initialization

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