cookie和session的使用

http://www.cnblogs.com/linguoguo/p/5106618.html

1:在控制器中添加session和cookie

    @RequestMapping("/getindex")
public String index(HttpServletRequest request){
Cookie cookie=new Cookie("name","liyafei");
HttpSession session = request.getSession();
session.setAttribute("name", "liyafei");
return "index";
}

2:jsp中打印出cookie和session

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
hello,index
<%
Cookie[] cookies=request.getCookies();
out.println(cookies[0].getValue()+"cookie");
out.println(session.getAttribute("name")+"session");
%>
</body>
</html>

3:结果
cookie和session的使用

   https://bbs.csdn.net/topics/390915878

上一篇:MPU6050首例整合性6轴的姿态模块(转)


下一篇:详解Python中的下划线