thymeleaf obtain user information from the session, thymeleaf obtain information from servletContext

Man of few words said, directly on the code

 

session

Back-end code:

// Create a session object is 
the HttpSession session = request.getSession ( to true ); 
session.setAttribute ( "the USER_INFO", userInfo); // save data to the user session object

Front-end code:

<span class="x-red"  th:text="${session.USER_INFO.uName}"/>

 

servletContext

Back-end code:

 servletContext.setAttribute("COUNT",val);

Front-end code:

<cite th:text="${#servletContext.getAttribute('COUNT')}">99</cite>

 

Guess you like

Origin www.cnblogs.com/book-mountain/p/11817117.html