1.Introduction
For convenienceProgramStaff accesses common objects, and implicitly objects are defined in JSP,These objects can be used directly without declaration.When converting from JSP to servlet, they will convert to the corresponding servlet type.
Out: indicates the output, which is equivalent to printwriter In the servlet. The corresponding type is javax. servlet. jsp. jspwriter.
Request: indicates the request information. The type of the request is javax. servlet. http. httpservletrequest.
Response: indicates the response information. The corresponding type is javax. servlet. http. httpservletresponse.
Session: Same as httpsession in servlet. The corresponding type is javax. servlet. http. httpsession.
Application: indicates the context of the entire application, which is equivalent to getservletconfig (). getservletcontext. The corresponding type is javax.. servlet. jsp. pagecontext.
Exception: Page exception, which can be used to obtain the exception information. The corresponding type is Java. Lang. throwable;
Page: indicates the JSP page, which has the same meaning as this in the Java class.
Pagecontext: the context of the JSP. The corresponding type is javax. servlet. jsp. pagecontext.
Config: indicates the servletconfig of the JSP. The corresponding type is javax. servlet. servletconfig.
Pagecontext, request, session, and application are four scope objects.
2.Request object
Let's talk about using it to pass values.
Request. setattribute ("name", "Guo ");
Request. getrequestdispatcher ("Address"). Forward (request, response );
In another page, you can receive: request. getattribute ("name ");
3.Session Object
The Session Object corresponds to the httpsession object. In JSP, the page command has an attribute related to the session, which is also called the session. If its value is set to false,
The session cannot be used on this JSP page.
Note that this is a built-in object, so you can directly use it without generating it.
Setattribute (Java. Lang. string name, java. Lang. Object value)
Getattribute (Java. Lang. string name) returns an object
4.Application
The application object is a global variable that is valid for Web applications. It implements the servletcontext interface. Note that it is global, that is, all clients access the same object.
Setattribute (Java. Lang. string name, java. Lang. Object value)
Getattribute (Java. Lang. string name) returns an object
5.Summary of four scope objects
If you place the variable inPagecontextIt indicates that its scope is page, and its valid range is only in the current JSP page. You can use this variable from placing the variable in pagecontext to the end of the JSP page.
If you place the variable inRequestIt indicates that its scope is request, and its valid range is the current request cycle. The request cycle refers to the whole process from initiating an HTTP request to processing the server and returning a response. In this process
The forward method redirects to multiple JSP pages. You can use this variable in these pages.
If you place the variable inSessionIt indicates that its scope is session, and its effective range is the current session. The current session refers to the process from when the user opens the browser to when the user closes the browser. This process may contain multiple
Request Response. That is to say, as long as the user is not in the browser, the server can know that these requests are initiated by a person. The whole process is called a session and put into the session variable, it can be used in all requests of the current session.
If you place the variable inApplicationIt indicates that its scope is application, and its effective scope is the whole application. The whole application refers to starting from the application to the end of the application, which can be simply understood as starting from the server, shut down the server.
6.Exception
The exception object is an instance of throwable, which indicates the exception information in JSP. Note that the implicit object exception is not available in all JSP pages. If you want to use
This object must set the iserrorpage attribute value of the JSP page command to true.
His use is as follows:
Error. jsp:
Set him to an error page: <% @ page iserrorpage = "true" %>
JSPCode: <%
Date = new date ();
Simpledateformat SDF = new simpledateformat ("mm minute SS seconds on mm dd, YYYY ");
String S = SDF. Format (date );
Out. println ("You have an error, please check ");
Out. println ("error time:" + S + "<br> ");
Out. println ("Error Type:" + exception );
%>
In the Web. xml file:
<Error-page>
<Exception-type> JAVA. Lang. throwable </exception-type>
<Location>/error. jsp </location>
</Error-page>
Through the above settings, the error information of the entire website can be concentrated in error. jsp for processing. Try to get an error page: index. jsp
<%
Int A = 3;
Out. println (A/0 );
%>