SpringMVC-向Session域中共享数据

阅读 37

2022-04-14

一、推荐使用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";
    }

}

在这里插入图片描述

精彩评论(0)

0 0 举报