Controller层
@Controller
public class DemoController {
@RequestMapping("/test")
public String test(HttpServletRequest request, Model model) {
request.setAttribute("req", "HttpServletRequest");
request.getSession().setAttribute("sess", "HttpSession");
request.getSession().getServletContext().setAttribute("app", "Application");
return "index";
}
}
Html视图层
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Thymeleaf语法详解-获取作用域对象中的数据</title>
</head>
<body>
Request:<span th:text="${#httpServletRequest.getAttribute('req')}"></span>
<hr/>
Session:<span th:text="${session.sess}"></span>
<hr/>
Application:<span th:text="${application.app}"></span>
</body>
</html>