<c:choose>
<c:when test="${empty login}">
<li><a href="../index/loginUI.do"><i class="fa fa-user"></i>/</a>
</li>
</c:when>
<c:otherwise>
<li><a href="../index/mycenter.do"><i class="fa fa-user"></i></a></li>
<li><a href="../index/logout.do"><i class="fa fa-user"></i></a>
</li>
</c:otherwise>
</c:choose>
this is what I wrote in JSTL, and it can run successfully without any exception
<li><a th:href="@{/login/loginUI}" th:if="${-sharphttpSession.login}eq null"><i class="fa fa-user-md"></i></a>
</li>
<li><a th:href="@{/index/loginUI}" th:if="${-sharphttpSession.login}eq null"><i class="fa fa-user"></i>/</a>
</li>
<li><a th:href="@{/index/mycenter}" th:unless="${-sharphttpSession.login} eq null"><i class="fa fa-user"></i></a></li>
<li><a th:href="@{/index/logout}" th:if="${-sharphttpSession.login} ne null"><i class="fa fa-user"></i></a>
</li>
but I can never find login when I use it in thymleaf
then my java code
@RequestMapping("/index")
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
Page page = new Page("filter_form");
page.setPageSize(8);
String currentPage = request.getParameter("page.currentPage");
if (StringUitl.IsNotNull(currentPage)) {
page.setCurrentPage(Integer.parseInt(currentPage));
}
//map
Map<String, Object> map = new HashMap<String, Object>();
map.put("page", page);
List list = changguanService.getForPage(map);
//
request.setAttribute("list", list);
request.setAttribute("paging", page.getPageStr());
System.out.println(page.getPageStr());
return new ModelAndView("index/index");
}
@RequestMapping("/login")
public void login(HttpServletRequest request, HttpServletResponse response, HttpSession httpSession) throws IOException {
String pwd = request.getParameter("pwd");
String no = request.getParameter("no");
response.setCharacterEncoding("utf-8");
Login login = (Login) httpSession.getAttribute("login");
if (login == null) {
User user = userService.checkUserNo(no, pwd);
if (user == null) {
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("<script>alert("");</script>");
response.getWriter().write("<script> window.location="../index/index" ;window.close();</script>");
response.getWriter().flush();
}
login = new Login(user.getId(), user.getName(), "user", "");
httpSession.setAttribute("login", login);
}
response.setContentType("text/html;charset=utf-8");
response.getWriter().write("<script>alert("");</script>");
response.getWriter().write("<script> window.location="../index/index" ;window.close();</script>");
response.getWriter().flush();
}
how can thymleaf realize the problem of directly judging the null value of an uncreated object by jstl