jsp上没有为添加的模型对象打印任何内容



我在下面得到了一个奇怪的行为:我在Spring Controller中添加了一个模型对象,当我在jsp中使用jstl访问它时,我在那里什么也得不到。

我的项目是基于REST的,构建在Java 1.8+Tomcat 8.0+Maven之上。

我的maven项目名为reporting,包含报告rest和报告dao的模块。Jsp页面和控制器位于报告休息区。

pom。报告rest 中的xml内容

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.reporting</groupId>
        <artifactId>reporting</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>reporting-rest</artifactId>
    <packaging>war</packaging>
    <properties>
        <servlet.version>2.5</servlet.version>
         <spring.version>3.2.4.RELEASE</spring.version>
        <log4j.version>1.2.17</log4j.version>
         <jdk.version>1.7</jdk.version>
        <context.path>SpringRestSecurityOauth</context.path>
        <spring.security.version>3.2.5.RELEASE</spring.security.version>
    </properties>
    <name>reporting-rest Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
    <!--    <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency> -->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>
        <!-- log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>1.0.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.10</version>
        </dependency>
        <dependency>
            <groupId>commons-httpclient</groupId>
            <artifactId>commons-httpclient</artifactId>
            <version>3.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
        <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>org.reporting.dao</groupId>
            <artifactId>reporting-dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>reporting-rest</finalName>
                <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-eclipse-plugin</artifactId>
                <version>2.9</version>
                <configuration>
                    <downloadSources>true</downloadSources>
                    <downloadJavadocs>false</downloadJavadocs>
                    <wtpversion>2.0</wtpversion>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${jdk.version}</source>
                    <target>${jdk.version}</target>
                </configuration>
            </plugin>
             </plugins>
    </build>
</project>

pom.xml报告(父级)中的内容

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.reporting</groupId>
    <artifactId>reporting</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
         <org.springframework.version>3.2.4.RELEASE</org.springframework.version> 
        <org.slf4j-version>1.7.5</org.slf4j-version>
        <org.json.version>20080701</org.json.version>
        <jackson-mapper.version>1.9.12</jackson-mapper.version>
        <jsp.version>2.2</jsp.version>
        <junit.version>4.11</junit.version>
        <org.postgresql.version>9.0-801.jdbc4</org.postgresql.version>
        <commons-dbcp.version>1.4</commons-dbcp.version>
        <cglib.version>2.2.2</cglib.version>
        <servlet.version>2.5</servlet.version>
        <spring-security.version>3.1.4.RELEASE</spring-security.version>
        <org.aspectj.version>1.6.12</org.aspectj.version>
        <spring-aop.version>3.2.5.RELEASE</spring-aop.version>
        <org.testng.version>6.8.7</org.testng.version>
        <spring-test.version>3.2.5.RELEASE</spring-test.version>
        <org.aspectj.version>1.6.2</org.aspectj.version>
        <env>dev</env>
        <project.parent.basedir>../</project.parent.basedir>
    </properties>
    <modules>
        <module>reporting-rest</module>
        <module>reporting-dao</module>
    </modules>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>${org.slf4j-version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
    </dependencies>
</project>

网络。xml文件

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:config/*-context.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>reporting</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>reporting</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
<!--    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping> -->
    <session-config>
        <session-timeout>60</session-timeout>
    </session-config>
</web-app>

用于报告rest 的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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:task="http://www.springframework.org/schema/task" xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd
                http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
                http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
                http://www.springframework.org/schema/security
                http://www.springframework.org/schema/security/spring-security-3.1.xsd">
    <context:component-scan base-package="org.reporting.rest" />
    <!-- <context:annotation-config/> -->
    <mvc:annotation-driven />
     <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
   </bean>
    </beans>

报告休息的控制器类

@Controller
@RequestMapping("/api/admin/")
public class AdminController {
    @RequestMapping(value = "/clients", method = RequestMethod.GET)
    public ModelAndView listClients() {
        ModelAndView model = new ModelAndView("clientDetails");
        //List<Client> clients=adminDAO.getClients();
        List<String> lists = new ArrayList<String>();
        lists.add("List A");
        lists.add("List B");
        lists.add("List C");
        lists.add("List D");
        lists.add("List 1");
        lists.add("List 2");
        lists.add("List 3");;
        model.addObject("lists",lists );
        model.addObject("matter","This is another matter" );
        return model;
    }
}

jsp视图位于报告rest 上

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<body>
    <h2>List Clients</h2>
    ${lists}
    Matter:: ${matter}
    <c:if test="${not empty lists}">
        <ul>
            <c:forEach var="listValue" items="${lists}">
                <li>${listValue}</li>
            </c:forEach>
        </ul>
    </c:if>
</body>
</html>

输出打印上方的jsp:

List Clients
${lists} Matter:: ${matter} 

没有内容被打印,并且在${}中得到了这样的东西

请帮忙。

使用<%@解决的问题页面为ELIgnored="false"%>。幸亏http://www.mkyong.com/spring-mvc/modelandviews-model-value-is-not-displayed-in-jsp-via-el/

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.4//EN"
 "http://java.sun.com/dtd/web-app_2_4.dtd" >
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<%@ page isELIgnored="false" %>
</head>
<body>
    <h2>List Clients</h2>
    <c:out value="${lists}"/>
    Matter:: ${matter}
    <c:if test="${not empty lists}">
        <ul>
            <c:forEach var="listValue" items="${lists}">
                <li>${listValue}</li>
            </c:forEach>
        </ul>
    </c:if>
</body>
</html>

相关内容

  • 没有找到相关文章

最新更新