common built-in objects and methods in JSP
First, out Object
There are only two common methods for this object:
1,out.print ("String");
2,out.println ("String");
The purpose is to send information to the client, that is, to display the information in the browser.
Second, Request Object
When a client requests a JSP page,a JSP container (such as TOMCAT) encapsulates the client's request information in the requests object.
Common methods are:
1,request.getparameter (String name); This method is used to obtain the parameters that the client sends to the server side, which has a name designation, usually a parameter in the form.
2,request.setcharacterencoding (String type); the character encoding used in the overloaded body. (Note: Before using request.getparameter () to obtain Chinese data, first use request.setcharacterencoding ("gb2312"); set character encoding, if not set it is possible garbled! )
3,request.getremoteaddr(); This method is primarily used to obtain the IP address of the client
Third, Response Object
encapsulates the JSP generates a response,the JSP establishes a default response object based on the client's request , and then sends the message to the client as requested by the corresponding client.
Common methods are:
1,response.sendredirect (String location); Redirects the client to a specific URL.
2,Response.addcookie (Cookie Cook); Add a cookie object to hold the client's information. Note:A cookie is an object residing on the client machine and contains status information, each cookie has a name, and each cookie can only be accessed by the website that generated it.
Four, Session Object
A session is a client-to-server conversation that starts from the client's connection to the server until it disconnects from the server. In general, when a user first logs on to the system,the JSP container assigns a unique SessionID to the user, which is used to differentiate the other user, and when the user exits,the ID will disappear.
Common methods are:
1,session.setattribute (String name, Object ob); binds an object to the Name property specified in the session
2,session.getattribute (String name); returns the property associated with the specified name
3,session.removeattribute (String name); to delete an object bound to a specified name in a conversation
Five, Application Object
save information for multiple users. For a JSP container, it holds all the user's shared information, which is different from the session object. The Application object is created when the server is started and is not extinct until the server shuts down.
1,applicaton.getattribute (String name); returns the property associated with the specified name
2,applicaton.setattribute (String name, Object ob); binds an object to the name property specified in the application
3,applicaton.removeattribute (String name); delete an object bound to the name specified in application
Common built-in objects and methods in JSP