一、推荐使用Servlet的API
二、项目测试
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1 th:text="${session.username}"></h1>
</body>
</html>
@Controller
public class MyController {
@RequestMapping(value = {"/index"})
public String index(HttpSession session){
session.setAttribute("username", "HttpSession");
return "index";
}
}