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>Titletitle>
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

thymeleaf抛出项目上下文ServletContext ,session,request等信息_第1张图片

 

 

 

 

 

你可能感兴趣的:(thymeleaf抛出项目上下文ServletContext ,session,request等信息)