在spring/mvc中,使用;模型";在jsp页面中
我在servlet中使用了以下方法:在spring/mvc中,使用;模型";在jsp页面中,jsp,spring-mvc,jstl,Jsp,Spring Mvc,Jstl,我在servlet中使用了以下方法: @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> myModel = new HashMap<String, Object>(); [...do something
@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);
}
@覆盖
受保护的ModelAndView HandlerRequestInternal(HttpServletRequest请求、HttpServletResponse响应)引发异常{
Map myModel=newhashmap();
[…做点什么…]
model.put(“msg”,“a message”);
返回新模型和视图(“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>
不空
空的
但我得到了这样的警告和错误:“测试不支持运行时表达式”
能帮我点忙吗?谢谢试试这个
<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" %>
请尝试使用最新的maven依赖项
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
jstl
jstl
1.2
?我已经看到${!空模型.field}工作。。。这是maven依赖项/标记库导入的区别吗?