JSP表达式语言不工作
我无法使JSP表达式语言不工作,jsp,spring-mvc,spring-3,Jsp,Spring Mvc,Spring 3,我无法使${}表达式在我的.jsp页面上工作 displayAllCustomers.jsp <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <body> <h3>Our Entire Customer Database</h3> <ul> <c:forEa
${}
表达式在我的.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>
我们的整个客户数据库
- ${customer.name}
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>
DisplayAllCustomerController.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);
}
}
公共类DisplayAllCustomerController{
私有CustomerManagementService CustomerManagementService;
public void setCustomerManagementService(CustomerManagementService CustomerManagementService){
this.customerManagementService=customerManagementService;
}
@请求映射(“/displayAllCustomers”)
公共模型和视图显示所有客户(){
List allCustomers=customerManagementService.getAllCustomers();
返回新模型和视图(“显示所有客户”、“所有客户”、“所有客户”);
}
}
当我显示页面时,只显示标题“我们的整个客户数据库”
这让我发疯,我不知道我错过了什么
有人能帮我理解为什么会这样吗
非常感谢。在顶部添加以下内容
<%@ page isELIgnored="false"%>
我错误地使用了错误的导入 我得到了
import org.springframework.web.portlet.ModelAndView代码>自动导入,当我认为我有org.springframework.web.servlet.ModelAndView代码>导入
这几乎把我逼疯了
谢谢。我遇到了一些问题,上面的解决方案奏效了。但问题是什么?我运行另一个项目,但不执行此导入。但它仍然可以正常工作
我指的是这个解决方案:
<%@ page isELIgnored="false"%>
> p>现在考虑使用JSP 3。x或以上。
您还使用了spring.io存储库中的springmaven
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>io.spring.repo.maven.release</id>
<url>http://repo.spring.io/release/</url>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
org.springframework.boot
SpringBootStarterWeb
io.spring.repo.maven.release
http://repo.spring.io/release/
假的
您必须检查maven库是否包含tomcat嵌入的el。
如果您没有使用spring的嵌入式tomcat服务器,那么请删除上述(tomcat嵌入式-*)库或编写新的pom依赖项
喜欢
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.1.6.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.1.6.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.1.6.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.1.6.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>4.1.6.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.1.6.RELEASE</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.1.6.RELEASE</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>io.spring.repo.maven.release</id>
<url>http://repo.spring.io/release/</url>
<snapshots><enabled>false</enabled></snapshots>
</repository>
</repositories>
org.springframework
spring上下文
4.1.6.1发布
运行时
org.springframework
弹簧芯
4.1.6.1发布
运行时
org.springframework
春豆
4.1.6.1发布
运行时
org.springframework
spring上下文支持
4.1.6.1发布
运行时
org.springframework
弹簧式
4.1.6.1发布
运行时
org.springframework
弹簧网
4.1.6.1发布
运行时
org.springframework
SpringWebMVC
4.1.6.1发布
运行时
io.spring.repo.maven.release
http://repo.spring.io/release/
假的
这应该管用 在顶部添加了
,但仍然不起作用。当我在控制台上打印数据库时,我正在从数据库中获取所有数据,但我无法显示它。您可以尝试以下两种方法吗,输出${allCustomers}
显示的是什么${code>null
,${allCustomers}
没有显示任何不应该显示的内容。allCustomers
在传递到displayAllCustomers.jsp
视图的Model
中迷失在哪里?如果我添加此项,我将获得在浏览器上看到的原始html文本。有人面临这个问题吗?web.xml中web应用标记的版本属性是什么?应该是这样的:您的标题与问题描述冲突。如果taglibs/EL不起作用,您可能会在webbrowser中通过右键单击>查看源代码生成的HTML输出中看到它们是原始的。这是真的吗?您在生成的HTML输出中看到了什么?您是否看到
?您是否看到${customer.name}
?如果你把${allCustomers}
简单地放在
里面会怎么样?@BalusC:我不知道我是不是错误地从org.springframework.web.portlet.portal
包中导入了ModelAndView
类,否则我就不会有这个标题来解决我遇到的问题。但你是对的。对我来说,是错误的导入导致了这个问题,我错误地导入了import org.springframework.web.portlet.ModelAndView代码>使用自动导入,我应该导入org.springframework.web.servlet.ModelAndView代码>。以上解决方案对我有效,但问题是什么..我已导入正确的ModelAndView。