Ali*_*t3r 2 jsp jstl spring-mvc
我在我的 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);
}
Run Code Online (Sandbox Code Playgroud)
现在在 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>
Run Code Online (Sandbox Code Playgroud)
但我收到此警告和错误:“测试不支持运行时表达式”
我可以帮忙吗?谢谢
试试这个,
<c:choose>
<c:when test="${not empty msg}">
<p> not empty </p>
</c:when>
<c:otherwise>
<p>empty</p>
</c:otherwise>
</c:choose>
Run Code Online (Sandbox Code Playgroud)
此外,如果未完成,您必须导入 JSTL 1.1。
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10741 次 |
| 最近记录: |