In spring/mvc using if-then-else statement on the "model" in a jsp page
10,910
Try with this,
<c:choose>
<c:when test="${not empty msg}">
<p> not empty </p>
</c:when>
<c:otherwise>
<p>empty</p>
</c:otherwise>
</c:choose>
Also, you must import JSTL 1.1 if not done.
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Author by
Alist3r
Updated on June 04, 2022Comments
-
Alist3r almost 2 years
i've this methodo in my servlet:
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> myModel = new HashMap<String, Object>(); [...do something...] model.put("msg","a message"); return new ModelAndView("myPage", "model", myModel); }
Now in my myPage.jsp i want to do an if-then-else on ${model.msg} and i've tryed to use JSTL in this way:
<c:choose> <c:when test="${!empty model.msg}"> <p> not empty </p> </c:when> <c:otherwise> <p>empty</p> </c:otherwise> </c:choose>
But i get this warning and error: "test does not support run time expressions"
can i've some help? Thanks