发表于: 2017-11-15 10:15:16
1 674
今天完成的任务
看了一下如何在网页上生成cookie
@RequestMapping("/hello.html")
public String helo(@CookieValue(defaultValue="0")Long hitCounter, HttpServletResponse response){
hitCounter++;
Cookie hit = new Cookie("hitCounter", hitCounter.toString());
hit.setHttpOnly(true); //如果设置了"HttpOnly"属性,那么通过程序(JS脚本、Applet等)将无法访问该Cookie
hit.setMaxAge(60 * 60); //设置生存期为1小时
response.addCookie(hit);
return "hello";
}
做了一个小示例
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>SpringMVC Cookie Demo</title>
</head>
<body>
<div align="center">
<h2>SpringMVC Cookie Demo</h2>
Page hit counter: <b> ${cookie.hitCounter.value} </b>
</div>
</body>
</html>
似乎cookie是一个存储于浏览器或者说用户本地的数据
每次打开网页都会因controller中的数据做改变,对登陆的保存就是根据这个做的
遇到的问题
收获
今天看的东西不多
评论