package cn.hbsi.dao.service;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;
import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class CookieDemo01
*/
public class CookieDemo01 extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
PrintWriter out = response.getWriter();
Cookie[] cookies = request.getCookies();
if(cookies!=null) {
out.write("你上一次访问的时间是:");
for(int i=0;i<cookies.length;i++) {
Cookie cookie=cookies[i];
if(cookie.getName().equals("lastLoginTime")) {
long lastLoginTime =
cookie访问(JavaWeb)
于 2022-02-17 10:47:20 首次发布
本文深入探讨了JavaWeb中Cookie的使用,包括创建、设置属性、读取和删除Cookie的详细步骤,以及Cookie在用户会话管理中的作用。通过实例代码展示了如何在后端开发中有效地利用Cookie进行状态维护。
摘要由CSDN通过智能技术生成