我在我的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);
}
现在在我的myPage.jsp中,我想在$ {model.msg}上做一个if-then-else,我试图以这种方式使用JSTL:
<c:choose>
<c:when test="${!empty model.msg}">
<p> not empty </p>
</c:when>
<c:otherwise>
<p>empty</p>
</c:otherwise>
</c:choose>
但我收到此警告和错误:“test不支持运行时表达式”
我可以帮忙吗?感谢答案 0 :(得分:4)
试试这个,
<c:choose>
<c:when test="${not empty msg}">
<p> not empty </p>
</c:when>
<c:otherwise>
<p>empty</p>
</c:otherwise>
</c:choose>
另外, 如果没有完成,你必须导入JSTL 1.1。
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
答案 1 :(得分:0)
请尝试使用最新的maven依赖。
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>