0
点赞
收藏
分享

微信扫一扫

SpringMVC-向Session域中共享数据

小云晓云 2022-04-14 阅读 37
后端java

一、推荐使用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 条评论