JSP Four scopes:
Page: The current page, that is, just jump to another page will not be valid
Request: A conversation, simple understanding is a request within the scope of the effective
Session: Browser process, as long as the current page is not closed (not enforced by the program), no matter how the jump is valid
Application: Server, as long as the server does not reboot (not forced to clear by the program), the data is valid
Built-in object features:
1. Provided by the JSP specification without the writer's instantiation.
2. Implementing and managing through Web containers
3. All JSP pages can be used
4. Use only in expressions or snippets of script elements (<%= uses built-in objects%> or <% to use built-in objects%>)
Nine commonly used built-in objects:
1. Output input object: Request object, Response object, out object
2. Communication Control object: PageContext object, Session object, Application object
3. Servlet object: Page object, config object
4. Error Handling object: Exception object
Object Common Method Description:
1.out objects (data flow javax.servlet.jsp.jspWriter)
Method name |
Description |
Print or println |
Output data |
NewLine |
Output line-Wrapping characters |
Flush |
Output buffer Data |
Close |
Turn off the output stream |
Clear |
Clears the data in the buffer but does not output to the client |
Clearbuffer |
Clears the data in the buffer and outputs it to the client |
GetBufferSize |
Get buffer size |
Getremaining |
Get the space in the buffer that is not occupied |
Isautoflush |
is automatic output |
2.request Object (Request information Javax.servlet.http.HttpServletrequest)
Method name |
Description |
IsUserInRole |
Determine if the authenticated user belongs to a member group |
GetAttribute |
Gets the value of the specified property, such as if the property value does not exist, returns null |
Getattributenames |
Gets a collection of all property names |
GetCookies |
Get all Cookie objects |
Getcharacterencoding |
Gets the character encoding of the request |
Getcontentlength |
Returns the length of the request body, such as an indeterminate return of-1 |
GetHeader |
Gets the specified name header value |
Getheaders |
Gets all the values of the specified name header, an enumeration |
Getheadernames |
Gets the names of all headers, an enumeration |
getInputStream |
Returns the request input stream, gets the data in the request |
GetMethod |
Get the method that the client transmits data to the server side |
GetParameter |
Gets the specified name parameter value |
Getparameternames |
Gets the name of all parameters, an enumeration |
Getparametervalues |
Gets all values for the specified name parameter |
Getprotocol |
Gets the protocol name that the client transmits data to the server side |
GetQueryString |
Gets the query string sent to the server as a Get method |
Getrequesturi |
Gets the client address that issued the request string |
Getremoteaddr |
Get the IP address of the client |
Getremotehost |
Get the name of the client |
GetSession |
To get and request related sessions |
getServerName |
Get the name of the server |
Getserverpath |
Get the path to the client request file |
Getserverport |
Get the port number of the server |
RemoveAttribute |
Delete a property in the request |
SetAttribute |
Set the specified name parameter value |
3.response Object (Response Javax.servlet.http.HttpServletResponse)
Method name |
Description |
Addcookie |
Add a Cookie Object |
AddHeader |
Add HTTP file Specify name header information |
Containsheader |
Determines whether the specified name HTTP file header information exists |
Encodeurl |
Using the SessionID package URL |
Flushbuffer |
Forces the current buffer content to be sent to the client |
GetBufferSize |
return buffer size |
Getoutputstream |
The output stream object returned to the client |
Senderror |
Sending an error message to the client |
Sendredirect |
To send a response to another location for processing |
setContentType |
Set the MIME type of the response |
SetHeader |
Sets the HTTP file header information for the specified name |
4.session Object (Session javax.servlet.http.HttpSession)
Method name |
Description |
getattribute |
Get the property of the specified name |
Getattributenames |
Get all the names of the properties in the session, an enumeration |
GetCreationTime |
Return session creation time |
GetId td> |
Get session identifier |
Getlastaccessedtime |
Return the last time the request was sent |
Getmaxinactiveinterval |
Return Session object Lifetime Unit 1 per thousand second |
Invalidate |
To destroy the Session object |
IsNew |
Whether each request produces a new Session object |
RemoveAttribute |
Remove properties for the specified name |
setattribute |
Set the property value of the specified name |
5.pageContext Object (page context Javax.servlet.jsp.PageContext)
Method name |
Description |
Forward |
Redirect to another page or servlet component |
GetAttribute |
Gets the property value of a specified name in a range |
Findattribute |
Search for properties of a specified name by range |
RemoveAttribute |
Deletes the property of a specified name in a range |
SetAttribute |
Sets the property value of a specified name in a range |
GetException |
Returns the current exception object |
Getrequest |
Returns the current Request object |
GetResponse |
Returns the current Response object |
Getservletconfig |
Returns the ServletConfig object for the current page |
Getservletcontext |
Returns the ServletContext object for all page shares |
GetSession |
Returns the session object for the current page |
6.application Objects (Application Javax.servlet.ServletContext)
Method name |
Description |
GetAttribute |
Gets the property value of the specified name in the Application object |
Getattributenames |
Gets the names of all the properties in the Application object, an enumeration |
Getinitparameter |
Returns the initial parameter value of the specified name in the Application object |
Getservletinfo |
Returns the current version information in the servlet compiler |
SetAttribute |
Sets the property value of the specified name in the Application object |
7.config Objects (configuration information for the servlet javax.servlet.ServletConfig)
Method name |
Description |
Getservletcontext |
Returns the Environment object for the servlet being executed |
Getservletname |
Returns the name of the servlet being executed |
Getinitparameter |
Returns the initial parameter value of the specified name |
Getinitparameternames |
Returns all the initial parameter names in the JSP, an enumeration |
8.page object (instance of current JSP, java.lang.object)
It represents a JSP that is compiled into a servlet that can be used to invoke the method defined in the Servlet class
9.exception Object (Run-time exception, java.lang.Throwable)
The result of the called Error page is only available in the error page.
That is, set in the page directive: <% @page iserrorpage= "true"%>
Request (Javax.servlet.ServletRequest) It contains information about browser requests. This object enables you to get the header information, cookies, and request parameters from the request.
Response (Javax.servlet.ServletResponse) The response returned to the user as a result of JSP page processing is stored in the object. and provides methods for setting response content, response headers, and redirects (e.g. cookies, headers, etc.)
Out (Javax.servlet.jsp.JspWriter) is used to write content to the output stream of a JSP page instance, providing several methods that you can use to echo the output to the browser.
PageContext (Javax.servlet.jsp.PageContext) describes the current JSP page's operating environment. You can return access to other implicit objects and their properties on a JSP page, and it also implements the method of transferring control from the current page to another page.
The Session object stores information about this session, or it can assign properties to a session, each with a name and a value of javax.servlet.http.HttpSession. Session objects are used primarily to store and retrieve property values.
Application (Javax.servle.ServletContext) stores contextual information about the servlet that runs the JSP page and any Web components that are in the same application.
Page (Java.lang.Object) represents the servlet instance of the current JSP page
Config (Javax.servlet.ServletConfig) This object is used to access the initialization parameters of the servlet instance.
Exception (Javax.lang.Throwable) when a page throws an exception, it is forwarded to the JSP error page, which is provided to handle the error in the JSP. The <% @page iserrorpage= "True" can only be used in the error page%>
JSP built-in Objects |
function |
Main Methods |
Out |
Output data to the client |
Print () println () flush () Clear () Isautoflush () GetBufferSize () Close () ... |
Request |
Requesting data from the client |
Getattributenames () getcookies () getparameter () getparametervalues () setattribute () ()-Getservletpath () ... |
Response |
Encapsulates the response generated by the JSP and is sent to the client to respond to the customer's request |
Addcookie () Sendredirect () setContentType () Flushbuffer () getbuffersize () Getoutputstream () Senderror () Containsheader () ........ |
Application |
|
|
Config |
Represents the configuration of the servlet, and when a servlet initializes, the container passes some information through this object to the servlet |
Getservletcontext () Getservletname () () Getinitparameter () Getinitparameternames () ..... |
Page |
An instance of the JSP implementation class, which is the JSP itself, through which it can be accessed |
Flush () ..... |
PageContext |
Wraps the context of the page for JSP pages. Managing the question of a named object that belongs to a particular visible part of a JSP |
Forward () getattribute () getexception () getrequest () GetResponse () Getservletconfig () GetSession () Getservletcontext () setattribute () RemoveAttribute () Findattribute () ........ |
Session |
Used to hold information for each user to track the operational status of each user |
GetAttribute () getId () Getattributenames () Getcreatetime () Getmaxinactiveinterval () Invalidate () IsNew () |
exception |
reflect the running exception |
GetMessage () ...... |