response: the response object
The method provides:
void addCookie (Cookie cookie); increase the cookie object server to the client
void sendRedirect (String location); throw IOExeption;: One way the page jump (redirects)
void setContentType (String type): Set the server type of contentType
The following is a need to be aware of when writing the following login details of the operation:
1.name attribute is used to reference an element in JavaScript, or a reference to the form data when the form is submitted.
Note: Only set the name attribute of the form element in order to pass their value when the form is submitted.
2.java equals the difference between the method and ==
With "==" to compare, the comparison is for the two variables of type String reference, that is to say if the two variable of type String, which they refer to the same String object (which points to the same memory heap), then "==" result of the comparison is true.
() Method to compare with equals Object object, String object inherits from Object, and of equals () method has been rewritten. When two objects by comparing String equals () method, in fact, the contents of the string String object encapsulated compared, i.e. the same as the String object if the two strings are encapsulated content (including the same case), then equals () method returns true.
The number of requests 12
Jump location server client-side issue occurred in the second jump
Redirect:
Server to get data from the client, the first response to the client, the client point to the new jump address success.jsp
The client second call request, success.jsp response to the client
Forwards the request:
The client requests the first request, the server to get the data, forward the request to success.jsp, success.jsp response to the client
index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.Date" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<form action="register.jsp" method="post">
用户名:<input type="text" name="uname"/><br/>
密码:<input type="password" name="upwd"/><br/>
<input type="submit" value="submit">
</form>
</body>
</html>
register.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <% //设置编码 request.setCharacterEncoding("utf-8"); String name=request.getParameter("uname"); String pwd=request.getParameter("upwd"); if(name.equals("z")&&pwd.equals("z")) { response.sendRedirect("success.jsp");//导致数据丢失 //request.getRequestDispatcher("success.jsp").forward(request,response); } %> <br/> </body> </html>
success.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>title</title>
</head>
<body>
登入成功!!
<%
//out.print(request.getParameter("uname"));
String name=request.getParameter("uname");
out.print(name);
%>
</body>
</html>
2.session (server)
Cookie (client, not the built-in object) Cookie is generated by the server, and then sent to the client saved
With respect to the role of local cache: Client -> server
For example, you will see a hello.mp4, for the first time to see when generated by the server and sent to the client, second look when the local have been retained
Role: to improve the efficiency of access to the server, but poor security
Cookie:name=value
public Cookie(String name,String value)
String getName () Gets name
String getValue() 获取value
void setMaxAge (int expiry); the maximum lifetime (sec)
Cookie server ready
response.addCookie(Cookie cookie)
Page jump (forward, redirect)
Client gets the cookie: request.getCookies ();
note:
1. increase server cookie: response object, the client get the object: request Object
2. can not directly acquire one simple object only once to get all of the cookie