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) |
Returns the initialization parameter of type string |
Public Java.util.Enumeration Getinitparameternames () |
Returns the names of all initialization parameters |
Public ServletContext Getservletcontext () |
Get the server applet environment for the current server applet or JSP page |
Public sring Getservletname () |
Get the name of the current server applet or JSP page |
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) |
Set the value of the Name property to |
Enumeration Getattributenamesinscope (int scope) |
Get Properties for all scope scopes |
Object getattribute (String name) |
Gets the value of the Name property |
void RemoveAttribute (String name) |
Remove the value of the Name property |
2. Method of Obtaining request parameter
Stringgetheader (Stringname) |
Get the header of name |
Enumerationgetheadernames () |
Get all the header names |
Enumerationgetheaders (Stringname) |
Gets the headers for all the name |
Intgetintheader (Stringname) |
Gets the header of the integer type name |
Longgetdateheader (Stringname) |
Gets the header of the date type name |
Cookie[]getcookies () |
Obtain cookies related to the request |
3. The ability to obtain the request HTTP header method
Stringgetcontextpath () |
Get the context path (that is, the platform name) |
Stringgetmethod () |
Method of getting HTTP (get, POST) |
Stringgetprotocol () |
Access to the protocol used (http/1.1, http/1.0) |
Stringgetquerystring () |
Gets the requested parameter string, however, the HTTP method must be a get |
Stringgetrequestedsessionid () |
Get the SessionID on the client side |
Stringgetrequesturi () |
Gets the URL of the request, but does not include the requested parameter string |
STRINGGETREMOTEADDR () |
Get the user's IP address |
Stringgetremotehost () |
Get the user's host name |
Intgetremoteport () |
Get the user's host port |
Stringgetremoteuser () |
Get the name of the user |
Voidetcharacterencoding (stringencoding) |
Set the encoding format to solve the problem of the form passing Chinese |
Four, response objects
response The object mainly passes the results of jsp processing data back to the client. The
response object is the implementation of the javax.servlet.http.httpservletresponse interface. Response the method provided by the object.
1. To set the table header method
Voidaddcookie (Cookiecookie) |
Add cookies |
Voidadddateheader (Stringname,longdate) |
New Long value to name header |
Voidaddheader (Stringname,stringvalue) |
New String type value to name header |
Voidaddintheader (Stringname,intvalue) |
New value of int type to name header |
Voidsetdateheader (Stringname,longdate) |
Specifies a long value to the name header |
Voidsetheader (Stringname,stringvalue) |
Specify string value to name header |
Voidsetintheader (Stringname,intvalue) |
Specifies the value of type int to the name header |
2. The method of setting the response status code
Voidsenderror (INTSC) |
Transfer Status code (STATUSCODE) |
Voidsenderror (INTSC,STRINGMSG) |
Transfer status codes and error messages |
Voidsetstatus (INTSC) |
Set the status code |
3. Method for URL rewriting (rewriting)
Stringencoderedirecturl (StringUrl) |
Encode URLs that use 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.
Voidclear () |
Clears the contents of the output buffer |
Voidclearbuffer () |
Clears the contents of the output buffer |
Voidclose () |
Turn off the output stream and clear all content |
Intgetbuffersize () |
Gets the current buffer size in kilobytes (KB) |
Intgetremaining () |
Gets the remaining buffer size (KB) after the current use |
Booleanisautoflush () |
The return true indicates that the buffer is automatically cleared when it is full; False indicates that no automatic cleanup and exception handling is generated |
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
Longgetcreationtime () |
Get the time that the session was generated, in milliseconds |
Stringgetid () |
Get the ID of the session |
Longgetlastaccessedtime () |
Get the time the user finally sent the request through this session |
Longgetmaxinactiveinterval () |
To get the maximum session inactivity time, and if this time is exceeded, sessions will expire |
Voidinvalidate () |
Cancel the Session object and discard the contents of the object completely |
Booleanisnew () |
To determine whether the session is "new" |
Voidsetmaxinactiveinterval (intinterval) |
To set the maximum session inactivity time, if more than this time, sessions will be invalidated td> |
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.
application Object implements the javax.servlet.servletcontext interface, ServletContext the method provided by the interface container
intgetmajorversion () |
container main servletapi version |
intgetminorversion () |
Get container minor Servletapi version |
Stringgetserverinfo () |
Gets the name and version of the container |
Stringgetmimetype (stringfile) |
Get the MIME type of the specified file |
Servletcontextgetcontext (stringuripath) |
Get applicationcontext | for the specified localurl
Stringgetrealpath (stringpath) |
Get absolute path to local path |
Voidlog (stringmessage) |
Writes information to the log file |
Voidlog (stringmessage,throwablethrowable) |
Writes exception information generated by StackTrace to the log file |
Eight, PageContext object
pagecontext objects can access other suppressed objects. The
1.pagecontext object accesses other suppressed object properties, at which point you need to specify a parameter for the range.
object getattribute (string name, int Scope)
enumeration getattributenamesinscope (int Scope)
void removeattribute (string name, int scope)
void setattribute (String name, Object value, int scope)
range parameters are four, representing four ranges: Page_scope, Request_scope, Session_scope, Application_scope
2.pagecontext objects Get methods for other suppressed objects
exceptiongetexception () |
Return the exception for the current page, but this page is errorpage, |
Jspwritergetout () |
Return the current page's output stream, for example: Out |
Objectgetpage () |
To return the servlet entity (instance) of the current Web page, for example: page |
Servletrequestgetrequest () |
Return the current Web page request, for example: request |
Servletresponsegetresponse () |
Return the response to the current page, for example: Response |
Servletconfiggetservletconfig () |
Return the current ServletConfig object for this page, for example: Config |
Servletcontextgetservletcontext () |
Return the current execution Environment (context) for this page, for example: application |
httpsessiongetsession () |
Return a session with a link to the current page, for example: Sessions |
3.PageContext object provides methods to obtain properties
Objectgetattribute (Stringname,intscope) |
Return the Name property, scoped to the Property object of scope, with the return type of object |
Enumerationgetattributenamesinscope (Intscope) |
Return property names of all properties scoped to scope, and the return type is enumeration |
Intgetattributesscope (Stringname) |
Property range with the return property name named |
Voidremoveattribute (Stringname) |
To remove a Property object with the property name named |
Voidremoveattribute (Stringname,intscope) |
Remove Property object with name, range as scope |
Voidsetattribute (Stringname,objectvalue,intscope) |
Specifies that the Property object has the name, value, and range as scope |
Objectfindattribute (Stringname) |
Look for property objects in all scopes with property names of name |
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 (Newjava.io.PrintWriter (out) |
Turn from click to open link