我对 JSTL 很陌生。
现在我已经创建了一个 HashMap 并在 jsp 页面中呈现它。
这就是我创建 HashMap 的方式
在应用层:
public HashMap<String, String> uploadSmelter(){
HashMap<String, String> progress = new HashMap<String, String>();
try {
CompanyEntity instanceNew = (CompanyEntity) sessionFactory.getCurrentSession()
.createCriteria(CompanyEntity.class)
.add(Restrictions.eq("name", smObj.getName()))
.add(Restrictions.eq("metal", MetalEnum.valueOf(metal))).uniqueResult();
if (instanceNew != null){
//logger.info();
progress.put("error", Integer.toString(1));
progress.put("errorMsg", "Company : " +smObj.getName() + " for Metal: " + metal + " exists." );
}
}
return progress
}
Run Code Online (Sandbox Code Playgroud)
在控制器级别:
HashMap<String, String> result = new HashMap<String, String>();
result.put("error", "0");
result.put("update", "0");
result.put("create", "0");
HashMap<String, String> progress = new HashMap<String, String>();
int number = 0;
while (rowIterator.hasNext())
{
progress= companyFacade.uploadSmelter(); // implemented in application level uploadSmelter method
if(progress.get("errorMsg")!=null){
result.put(Integer.toString(number),progress.get("errorMsg"));
}
number=number+1 ;
}
Run Code Online (Sandbox Code Playgroud)
现在终于如果我在jsp页面打印它,我得到
{3=Company: ABC COMPANY for Metal: A Exists, update=0, 2=Company: ABC COMPANY TIN for Metal TIN Exists, 1=Company: ABC COMPANY G for Metal METAL_TANTALUM Exists, 0=Company: ABC COMPANY L for Metal METAL_TANTALUM Exists, error=4, fileName=data.1407219942830.xls, number=4, create=0}
Run Code Online (Sandbox Code Playgroud)
现在我想在 jsp 页面中运行一个 foreach 循环,该循环应该从 Hashmap 打印过滤值。
所以我在 JSTL if 语句中添加了这些条件。但似乎它不支持条件语句,我没有得到任何输出。
<c:forEach items="${result}" var="item">
<c:if test="${item.key} !='update' && ${item.key} !='error' && ${item.key} !='create' && ${item.key} !='number' && ${item.key} !='fileName'}" >
<div class="attributeField">Line Number <c:out value="${item.key}" /> <spring:message message="${item.value}"/></div>
</c:if>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
那么我在做什么错误?感谢您提前提供帮助。
只需使用 single${...}围绕所有条件作为test属性值。
示例代码:
<c:forEach items="${result}" var="item">
<c:if
test="${item.key !='update' && item.key !='error' && item.key !='create' && item.key !='number' && item.key !='fileName'}">
...
</c:if>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)
&&只能在里面执行${...}。