1.JSP built-in objects: out, request, response, page, session, Exception, Application, config, PageContext.
Built-in objects are the core knowledge of JSPs, because many of the features in JSP pages are encapsulated in the JSP's built-in objects.
- What is the difference between a built-in object and an object in the Java language?
- The instantiation of the JSP built-in object is given to the Web container, and the programmer can call it directly when writing the JSP page, without instantiating it;
- A call to a Java object must be instantiated with new before it can be used.
2.out output object.
- Print () method
- println () method
- Methods for managing the corresponding buffers: Clear (), Clearbuffer (), flush (), etc.
3.request object.
The request object encapsulates all the details of HTTP requests generated by the client, including HTTP header information, request methods, request parameters, and so on. Information in client requests can be obtained by means of the request object.
- Form-action: Used to set the submission address of the form;
- Form-method: Used to specify the way to commit, post/get.
- Request-getparameter ()
4.response object.
The response object is used to respond to customer requests and output information to the client. It encapsulates the response generated by the JSP and sends it to the client in response to the client's request. The response object is valid within the JSP page.
- Operation of HTTP header information
• Set the page to automatically refresh <% response.setheader ("refresh"); %>• Timed jump page <% response.setheader ("refresh""5,url= login.jsp"); %>
- Set MIME type: By default, a JSP page takes a content type of text/html and modifies the format as follows:
response.setcontenttype (String type); // type: text/html, Text/plain, Application/x_msexcel, Application/msword, etc.
- Page redirection action: Use the Sendredirect () method provided by the response object to redirect the Web page to another page:
Response.sendredirect (String path);
5. Session Object Application
The HTTP protocol is a stateless protocol, that is, when a customer sends a request to the server, the server accepts the request and returns the response, the row ends, and the server does not save the relevant information.
- Session cycle: The same browser until the browser is closed;
- Creation and acquisition of sessions: The Session object can be used to access or read information about the customer: SetAttribute (), getattribute ():
Session.setattribute (String name, Object obj)//name is the variable name used to specify the scope of the session, and obj is the object that is held in the session scope//Session.setattribute ("Usename", "no Words");getattribute (String name)//Session.getattribute ("username");//Note: The GetAttribute method returns an object type, not a string, so it can be converted with ToString () or coercion typeString user = (string) Session.getattribute ("username"); String User= Session.getattribute ("username"). ToString ();
- Move out of data in session:
removeattribute (String name) // Name: The variable name used to specify the scope within the session range. Make sure that the variable is valid within the session range, otherwise it will throw an exception
6. Application of Application objects
Application is similar to a system-wide global variable that is created when the server is started and destroyed when the server is stopped.
Application.setattribute (String name, Object obj); Application.getattributenames (); • Application.getattribute ().
JSP built-in objects