在jsp上无法访问ModelAttributes [英] ModelAttributes not accessible on jsp

查看:93
本文介绍了在jsp上无法访问ModelAttributes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用MAven和Im创建了一个新的Spring MVC项目,其中的一个问题是在jsp页面上没有替换modelAttributes。例如,

Created a new Spring MVC project using MAven and Im having a problem where the modelAttributes are not getting substituted on the jsp page. For eg.,

<%@ page session="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html" %>

Hello Worlds ${location} is ${weathers}
<c:out value="${location}"/>

显示

Hello Worlds ${location} is ${weathers}
${location}

而不是

Hello Worlds Omaha is Cold
Omaha

我猜我错过了一个jar,我在mvn依赖列表中有以下内容:

I'm guessing I'm missing a jar, I have the following in the mvn dependency list :


   <dependency>
       <groupId>taglibs</groupId>
       <artifactId>standard</artifactId>
       <version>1.1.2</version>
   </dependency>
   <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-servlet_2.4_spec</artifactId>
       <version>1.1.1</version>
   </dependency>
   <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.4</version>
       <scope>provided</scope>
   </dependency>
   <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring</artifactId>
       <version>2.0.7</version>
   </dependency>
   <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-webmvc</artifactId>
       <version>2.5.5</version>
   </dependency>



推荐答案

我是引用回答我之前提到EL不能正常工作的问题:

I'm quoting from an answer I provided before to the problem of EL not working:


换句话说,EL表达式没有得到评估?这可能有以下一个或多个原因:

With other words, the EL expression doesn't get evaluated? That can have one or more of the following causes:


  1. 有问题的应用程序服务器不支持JSP 2.0。

  2. web.xml 未声明为Servlet 2.4或更高版本。

  3. @ page 配置为 isELIgnored = true

  4. web.xml配置为< el-ignored> true< / el-ignored> in < jsp-config>

  1. Application server in question doesn't support JSP 2.0.
  2. The web.xml is not declared as Servlet 2.4 or higher.
  3. The @page is configured with isELIgnored=true.
  4. The web.xml is configured with <el-ignored>true</el-ignored> in <jsp-config>.


在您的特定情况下,1)可能会被划伤。 3)和4)太明显无法监督,因此也可能被划伤。留下第2点)。您的 web.xml 显然是使用旧版本声明的。确保 web.xml 被声明为至少 Servlet 2.4:

In your particular case, 1) can be scratched. 3) and 4) are too obvious to be overseen, so that can likely be scratched as well. Left behind point 2). Your web.xml is apparently declared with an older version. Ensure that your web.xml is declared as at least Servlet 2.4:

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

    <!-- Here you go. -->

</web-app>

这篇关于在jsp上无法访问ModelAttributes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆