Implied object __jsp of a JSP

Source: Internet
Author: User
Tags data structures exception handling session id sessions stack trace throwable

One, Page object

The Page object represents the JSP itself, or rather, it represents the JSP-translated servlet, which can invoke the method defined by the Servlet class.


Two, config object
The Config object holds some of the servlet's initial data structures.
The Config object is implemented in the Javax.servlet.ServletConfig interface, which has the following four methods:


Public String Getinitparameter (name)
Public Java.util.Enumeration Getinitparameternames ()
Public ServletContext Getservletcontext ()
Public sring Getservletname ()

Third, Request object
The Request object contains all the requested information, such as the source of the request, the header, the cookies and the parameter values associated with the request, and so on.
The request object implements the Javax.servlet.http.HttpServletRequest interface, and the method provided can divide it into four main categories:

1. Methods of storing and acquiring property;


void SetAttribute (String name, Object value) sets the value of the Name property to
Enumeration Getattributenamesinscope (int scope) Gets the properties of all scope scopes
Object getattribute (String name) Gets the value of the Name property
void RemoveAttribute (String name) removes the value of the Name property


2. Method of Obtaining request parameter


String GetParameter (string name) gets the parameter value of name
Enumeration Getparameternames () get all the parameter names
string [] getparametervalues (string name) gets the parameter value of all name
Map Getparametermap () Gets a map that requires parameters

3. The ability to obtain the request HTTP header method


String GetHeader (string name) gets the header of name
Enumeration Getheadernames () get all the header names
Enumeration Getheaders (String name) gets the headers for all the name
int Getintheader (String name) Gets the header of the integer type name
Long Getdateheader (String name) Gets the header of the date type name
Cookies [] getcookies () obtain cookies related to the request

4. Other methods


String Getcontextpath () Gets the context path (that is, the platform name)
String GetMethod () method of obtaining HTTP (GET, POST)
String Getprotocol () acquisition of the protocol used (http/1.1, http/1.0)
String getquerystring () gets the requested parameter string, but the HTTP method must be a get
String Getrequestedsessionid () Gets the session ID of the client
String Getrequesturi () gets the URL of the request, but does not include the requested parameter string
String getremoteaddr () Gets the user's IP address
String Getremotehost () Gets the user's host name
int Getremoteport () Gets the user's host port
String Getremoteuser () Gets the name of the user
void etcharacterencoding (String encoding) set encoding format to solve problems with forms passing Chinese

Iv. Response Objects
The response object mainly passes the results of the JSP processing data back to the client.
The response object is the implementation Javax.servlet.http.HttpServletResponse interface. Response the method provided by the object.
1. Set the table head method
void Addcookie (Cookie cookie) New cookie
void Adddateheader (String name, long date) new value of long type to name header
void AddHeader (string name, String value) new String value to name header
void Addintheader (String name, int value) adds value of type int to name header
void Setdateheader (String name, long date) specifies a long value to the name header
void SetHeader (string name, string value) specifying String value to name header
void Setintheader (String name, int value) Specifies the value of type int to the name header
2. The method of setting the response status code
void Senderror (int sc) Transfer status code (status code)
void Senderror (int sc, String msg) transfer status code and error message
void SetStatus (int sc) set state code
3. Method for URL rewriting (rewriting)
String encoderedirecturl (string url) encodes a URL that uses the Sendredirect () method

Five, out objects
An Out object can output the results to a Web page.
Out is mainly used to control the output stream of buffers (buffer) and output streams.
void Clear () clears the contents of the output buffer
void Clearbuffer () clears the contents of the output buffer
void Close () closes the output stream and clears all content
int getbuffersize () gets the current buffer size (KB)
int getremaining () Gets the remaining buffer size (KB) after the current use
The Boolean Isautoflush () return True indicates that the buffer is automatically cleared when it is full; False indicates that it will not automatically purge and cause exception handling

Six, Session Object
The Session object represents the current sessions status of individual users.
The session object implements the Javax.servlet.http.HttpSession interface, the method provided by the HttpSession interface
Long GetCreationTime () Gets the time that the session was generated, in milliseconds
String getId () Gets the ID of the session
Long Getlastaccessedtime () Gets the time the user finally sent the request through this session
Long Getmaxinactiveinterval () to get the maximum session inactivity time, if more than this time, sessions will be invalidated
void invalidate () cancels the session object and discards the contents of the object completely
Boolean isnew () to determine whether the session is "new"
void setmaxinactiveinterval (int interval) sets the maximum session inactivity time, if more than this time, sessions will be invalidated

Vii. Application objects
Application objects are most commonly used in accessing information in the environment.
Because information about the environment is usually stored in ServletContext, application objects are often used to access information in ServletContext.
The Application object implements the Javax.servlet.ServletContext interface, ServletContext the method provided by the interface container
int getmajorversion () obtains container main servlet API version
int getminorversion () gets container minor servlet API version
String Getserverinfo () gets the name and version of container
String GetMimeType (string file) gets the MIME type of the specified file
ServletContext getcontext (String uripath) Gets the application context of the specified local URL
String Getrealpath (string path) gets the absolute path of the local path
void log (String message) writes the information to the log file
void log (String message, throwable throwable) writes the exception information generated by stack trace to the log file

Eight, PageContext object
PageContext objects can access other suppressed objects.
1.pageContext object to access other suppressed object properties, you need to specify a range of parameters.
Object getattribute (String name, int scope)
Enumeration Getattributenamesinscope (int scope)
void RemoveAttribute (String name, int scope)
void SetAttribute (String name, Object value, int scope)
There are four range parameters, representing four different ranges: Page_scope, Request_scope, Session_scope, Application_scope
2.PageContext object method for obtaining other suppressed objects
Exception getexception () return the exception to the current page, but this page will be the error page,
JspWriter getout () return the current page's output stream, for example: out
Object GetPage () The servlet entity (instance) that is returning the current page, for example: page
ServletRequest getrequest () to return the current Web page request, for example: request
Servletresponse GetResponse () the response to the current page, for example: response
ServletConfig Getservletconfig () return the current ServletConfig object for this page, for example: Config
ServletContext Getservletcontext () Return the current execution Environment (context) for this page, for example: application
HttpSession getsession () the Conversation (session) that is associated with the current Web page, for example: Sessions
3.PageContext object provides methods to obtain properties
Object GetAttribute (String name, int scope) to return the Name property, scoped to the Property object of scope, with the return type of object
Enumeration Getattributenamesinscope (int scope) return the name of all properties scoped to scope, and the return type is enumeration
int Getattributesscope (String name) property range with name return property
void RemoveAttribute (String name) removes a Property object with the property name named
void RemoveAttribute (String name, int scope) Removes a Property object with the name of the property named, scoped to scope
void SetAttribute (String name, Object value, int scope) specifies that the name of the Property object is named, values is value, range is scope
Object Findattribute (String name) looks for property objects with name names in all scopes

Nine, exception objects
To use the exception object, you must set it in the page directive. <%@ page iserrorpage= "true"%> to use.
The three methods offered by exception are:
GetMessage ()
Getlocalizedmessage (),
Printstacktrace (New Java.io.PrintWriter (out))

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.