Request:
The server accepts data transmitted by the client in HTTP mode.
Common methods: +getparameter (String args): String, +getparametervalues (): string[], +getparameternames (): enumeration;
The request is actually processed further after the server accepts the information requested by the client.
1, solve the problem of garbled
Hello:<%=request.getparameter ("name")%>
So directly write garbled problem: Hello: Indent?
This is the time to use
public void setcharacterencoding (String env)
Throws unsupportedencodingexception to set the agreed encoding format.
Note : The request code set here will be the same as your JSP encoding format in order to not garbled.
<%request.setcharacterencoding ("UTF-8");%>hello:<%=request.getparameter ("name")%>
Result: Hello: Dare
2. Transfer parameters:
Get a parameter to the form: +getparameter (String args): string (hidden Form form field)
String name = Request.getparameter ("username");
Get multiple parameters for the form: +getparameternames (): enumeration;
enumeration<string> Enume = Getparameternames ();
Get passed content is array: +getparametervalues (): string[] (for drop-down list, check box, etc.)
String [] param = getparametervalues ();
Summarize:
As long as the client information, on the server side can be obtained through the request object
Response: The server wants the client to send messages, HTTP header information, cookies, etc.
Main use:
REDIRECT Response.senddirection (Loc): Response.sendredirect ("firstcookie.jsp");
Set the response header: Use this to refresh the page, jump after two seconds, and so on.
Set Cookies:response.addCookie (cookie);
Summary: The server wants the message sent by the client to be set by response.
The SESSION:HTTP protocol is stateless, and he does not know that every browser requested is not the same browser.
Use: Saves various information about the user until his lifetime expires or is freed.
The session object belongs to the instantiated object of the Javax.servlet.http.HttpSession interface.
The main methods of the session:
Method: Session.getid () Gets an ID that is assigned by the server.
public Boolean isnew () is not a new session
Set Properties: Session.setsetattribute (string name, string value); Request.getsession (). SetAttribute ("token", tokenvalue);
Get property: Public Object getattribute (String name) request.getsession (). getattribute ("message")
Delete property: Public Object removeattribute (String name) session.removeattribute ("message");
Session Expiration:
If the session fails, all the operations held at the session will disappear.
public void Invalidate (): Invalidates session (manual)
Other methods of the session can be viewed in the servlet API.
The difference between a session and a cookie:
The session exists on the server side and the cookie exists on the client.
Sessions are safer than cookies, but waste more space and resources than cookies.
The session should be used sparingly-save information to the session as little as possible
The session uses a cookie mechanism, and if the cookie is disabled, the session is not available
Application: Same as session is also used to save the message, but it saves the message is everyone can share, and the session of the private. (Number of people online)
As long as it works: Save public messages
Three ways to manipulate properties:
SetAttribute (), getattribute (), RemoveAttribute ()
Out: Dynamically outputting some content to the JSP page.
Our.print ("Hello:" +name), but this should be used less and can be replaced with Hello:<%=name%>.
Config: Handles configuration information in Web. Xml.
The Config method can be implemented by looking at the API. Javax.servlet.ServletConfig
method to get initialization parameters: public string Getinitparameter (string name)
Get all parameters: Public enumeration getinitparameternames ();
Other less used not in the description;
Javaweb Learning--jsp Nine large built-in objects