我很难将模型值从控制器显示到JSP视图。一切都在Tomcat 6中工作,但在Tomcat 5.5中却不起作用。这是我的档案。
用于Tomcat5.5的web.xml (对于Tomcat 6,我使用了version="2.5“和正确的模式)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">版本:
Tomcat:5.5
Taglib:jstl.jar,standard.jar (1.1版)
控制器
@Controller
@RequestMapping("/inventory")
public class SimpleController {
@Autowired
@Qualifier("inventoryService")
private IInventoryService inventoryService;
// Our default method when a simple GET request is made to /simple
@SuppressWarnings("unchecked")
@RequestMapping(method = RequestMethod.GET)
public String viewProducts(ModelMap model) {
List<IInventory> retrieved = inventoryService.getInventories();
List <InventoryDTO> inventories = new ArrayList();
for (IInventory inventory: retrieved) {
InventoryDTO inventoryDTO= new InventoryDTO();
inventoryDTO.setId(inventory.getId());
inventoryDTO.setBrandName(inventory.getBrand().getName());
inventories.add(inventoryDTO);
}
model.put ( "inventories", inventories );
// This will resolve to a logical view name /WEB-INF/jsp/inventoriesView.jsp
return "inventoriesView";
}
}inventoriesView.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
<head>
<style type="text/css">
<%@include file="../../resources/style.css" %>
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Inventories</title>
</head>
<body>
<h1>Inventory</h1>
<br/>
<%@include file="menu.jsp" %>
<br /><br />
<c:if test="${!empty inventories}" >
<table class="table" border="1">
<tr>
<th>ID</th>
<th>Brand</th>
</tr>
<c:forEach items="${inventories}" var="inventory">
<tr>
<td><c:out value="${inventory.id}" /></td>
<td><c:out value="${inventory.brandName}" /></td>
</tr>
</c:forEach>
</table>
</c:if>
<c:if test="${empty inventories}">
There are currently no inventories.
</c:if>
</body>
</html>记住,这在Tomcat6.0中是完美的,但在Tomcat5.5中却不是。我没有任何错误。它只是不会像模型为null一样显示数据。当我调用EL表达式{2+2}时,我得到4作为Tomcat5.5和6的值。
发布于 2010-09-27 19:35:42
我猜您的/WEB-INF/lib中有一个Tomcat 6特定的EL JAR文件,这导致了Tomcat 5.5中的EL empty关键字失败。确保您的/WEB-INF/lib没有特定于specific容器的库。我还将检查Tomcat5.5日志中的任何启动和webapp初始化期间的失败。这些内容本身并不代表在webapp错误页面中。
发布于 2011-08-03 11:52:21
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
<scope>compile</scope>
</dependency>https://stackoverflow.com/questions/3805548
复制相似问题