zoukankan      html  css  js  c++  java
  • thymeleaf抛出项目上下文ServletContext ,session,request等信息

        @RequestMapping("/alls")
        public String allsinfo(HttpSession session, HttpServletRequest request,Model model){
            session.setAttribute("username","小张session");
            request.setAttribute("userpwd","666req");
            request.getServletContext().setAttribute("usersex","男ctx");
            String paths = request.getServletContext().getContextPath();
            model.addAttribute("paths",paths);
            return "allsinfo";
        }
    <!DOCTYPE html>
    <html lang="en" xmlns:th="http://www.thymeleaf.org">
    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>
    <body>
        <div>请求上下文内容</div>
        <div th:text="${#httpServletRequest.getAttribute('userpwd')}"></div>
        <div th:text="${userpwd}"></div>
        <div th:text="${session.username}"></div>
        <div th:text="${#servletContext.getAttribute('usersex')}"></div>
        <div th:text="${application.usersex}"></div>
    </body>
    </html>

    这里需要注意的是有两种request取法,两种servletcontext取法,一种session

  • 相关阅读:
    js倒计时
    web前端基本开发手册
    快速了解CSS3当中的HSLA 颜色值怎么算
    IDEA快捷键
    3 认识的本质及其规律
    2 世界的物质性及其发展规律
    1 绪论
    9 数据库连接池
    8 代码实现事务
    7 IDEA连接数据库
  • 原文地址:https://www.cnblogs.com/xiaozhang666/p/12021862.html
Copyright © 2011-2022 走看看