【发布时间】:2012-01-05 15:53:05
【问题描述】:
我无法在我的 .jsp 页面上使用 ${} 表达式。
displayAllCustomers.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<body>
<h3>Our Entire Customer Database</h3>
<ul>
<c:forEach items="${allCustomers}" var="customer">
<li>${customer.name}</li>
</c:forEach>
</ul>
</body>
</html>
dispatcher-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<import resource="applicationContext.xml"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="/displayAllCustomers" class="mypackage.DisplayAllCustomersController">
<property name="customerManagementService" ref="customerManagementService" />
</bean>
</beans>
DisplayAllCustomersController.java
public class DisplayAllCustomersController {
private CustomerManagementService customerManagementService;
public void setCustomerManagementService(CustomerManagementService customerManagementService) {
this.customerManagementService = customerManagementService;
}
@RequestMapping("/displayAllCustomers")
public ModelAndView displayAllCustomers() {
List<Customer> allCustomers = customerManagementService.getAllCustomers();
return new ModelAndView("displayAllCustomers", "allCustomers", allCustomers);
}
}
当我显示页面时,我只显示标题“我们的整个客户数据库”。
这让我发疯,我无法弄清楚我错过了什么。
有人可以帮我理解为什么会这样吗?
非常感谢。
【问题讨论】:
-
您的标题与问题描述冲突。如果 taglibs/EL 不工作,你会在 webbrowser 中通过右键单击 > View Source 在生成的 HTML 输出中看到它们。这是真的?您在生成的 HTML 输出中看到了什么?你看到
<c:forEach>了吗?你看到${customer.name}了吗?如果你把${allCustomers}放在<h3>里面呢? -
@BalusC:我不知道我错误地从
org.springframework.web.portlet.portal包中导入了ModelAndView类,否则我遇到的问题不会有这个标题。但你是对的。
标签: jsp spring-mvc spring-3