gpt4 book ai didi

Spring MVC 3 JSTL 不会在 Tomcat 5.5 中输出值

转载 作者:行者123 更新时间:2023-11-28 22:23:26 25 4
gpt4 key购买 nike

我在将模型值从我的 Controller 显示到我的 JSP View 时遇到困难。在 Tomcat 6 中一切正常。但在 Tomcat 5.5 中不起作用。这是我的文件。

web.xml 用于 Tomcat 5.5(对于 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

标签库:jSTL.jar、standard.jar(1.1版本)

Controller

@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>

请记住,这在 Tomcat 6.0 中可以完美运行,但在 Tomcat 5.5 中则不行。我没有收到任何错误。它只是不会像模型为空一样显示数据。当我调用 EL 表达式 {2+2} 时,我得到 4 作为 Tomcat 5.5 和 6 的值。谢谢

最佳答案

猜测您的/WEB-INF/lib 中有一个Tomcat 6 特定的EL JAR 文件,这导致-除其他外-EL 为空 关键字在 Tomcat 5.5 中失效。确保您的 /WEB-INF/lib 没有特定于 servletcontainer 的库。我还会检查 Tomcat 5.5 日志以了解在启动和 webapp 初始化期间是否有任何故障。这些本身不会在 webapp 错误页面中表示。

关于Spring MVC 3 JSTL 不会在 Tomcat 5.5 中输出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3805548/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com