-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionDemo03.java
More file actions
30 lines (26 loc) · 897 Bytes
/
Copy pathSessionDemo03.java
File metadata and controls
30 lines (26 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package session;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;
/**
* @author : CodeWater
* @create :2022-03-15-16:47
* @Function Description :
*/
@WebServlet("/sessionDemo03")
public class SessionDemo03 extends HttpServlet {
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
HttpSession session = req.getSession();
System.out.println(session);
// 期望客户端关闭后,session也能相同
Cookie c = new Cookie("JSESSIONID", session.getId());
c.setMaxAge(60 * 60);
resp.addCookie(c);
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req, resp);
}
}