JSP:不评估EL(而不是显示变量“$ message”的值)

时间:2015-11-19 14:51:15

标签: jsp el

我在JSP页面上评估EL时遇到问题。 而不是价值“Hello world!”我看到变量“$ message”。

我试图找到解决此问题的可能原因和解决方案:

  1. 应用程序服务器。检查应用程序服务器 - 我使用Tomcat 8.0.28 - 它应该支持JSP 2.0。我还尝试用划痕创建一个新的简单弹簧mvc应用程序 - 在这种情况下评估EL。
  2. web.xml描述符我使用“web-app_3_1.xsd”。
  3. 页面指令isELIgnored 我试图将此指令(<%@ page isELIgnored =“true | false”%>)添加到JSP页面,它使情况变得更糟 - 这个表达式和整体html代码显示在页面上。
  4. 我还尝试将以下代码添加到web.xml

    <jsp-config>
    <jsp-property-group>
        <url-pattern>*.jsp</url-pattern>
        <el-ignored>false</el-ignored>
    </jsp-property-group>
    

  5. 没有任何帮助:)

    也许问题可能与pom.xml有某种关系,因为有太多的依赖可能会发生冲突。

    非常感谢任何帮助。

    project structure (image)

    testController.jsp

    package net.kuriculo.controller;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    
    @Controller
    @RequestMapping("/test")
    public class testController {
        @RequestMapping(method = RequestMethod.GET)
        public String printWelcome(ModelMap model) {
            model.addAttribute("message", "Hello world!");
            return "test";
        }
        }
    

    test.jsp的

    <html>
    <head>
        <title></title>
    </head>
    <body>
    <h1>${message}</h1>
    </body>
    </html>
    

    的web.xml

    <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1">
    
        <display-name>kuriculo</display-name>
    
        <servlet>
            <servlet-name>kuriculo</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>kuriculo</servlet-name>
            <url-pattern>*.jsp</url-pattern>
        </servlet-mapping>
    
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    
    </web-app>
    

    的pom.xml

    <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>net.kuriculo</groupId>
        <artifactId>kuriculo</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <packaging>war</packaging>
    
        <properties>
            <!-- Spring Security is based on Spring 3.0.7 -->
            <!--<spring.version>3.2.8.RELEASE</spring.version>-->
            <spring.version>4.1.1.RELEASE</spring.version>
            <spring.security.version>3.2.3.RELEASE</spring.security.version>
            <jersey.version>1.18.1</jersey.version>
            <org.slf4j.version>1.7.7</org.slf4j.version>
            <org.hibernate.version>4.3.5.Final</org.hibernate.version>
            <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
            <org.hsqldb.version>2.3.2</org.hsqldb.version>
            <commons-dbcp.version>1.4</commons-dbcp.version>
            <junit.version>4.11</junit.version>
            <org.eclipse.jetty.jetty-maven-plugin.version>9.1.1.v20140108</org.eclipse.jetty.jetty-maven-plugin.version>
        </properties>
    
    
        <licenses>
            <license>
                <name>The Apache Software License, Version 2.0</name>
                <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
                <distribution>repo</distribution>
            </license>
        </licenses>
    
        <prerequisites>
            <maven>2.2.1</maven>
        </prerequisites>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>${maven-compiler-plugin.version}</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.eclipse.jetty</groupId>
                    <artifactId>jetty-maven-plugin</artifactId>
                    <version>${org.eclipse.jetty.jetty-maven-plugin.version}</version>
                </plugin>
            </plugins>
        </build>
    
        <scm>
            <developerConnection>scm:git:https://github.com/nshkuratova/KURICULO.git</developerConnection>
        </scm>
    
        <dependencies>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
            <!-- Huh? Spring Jdbc is suddenly marked as provided by spring-orm? -->
             <dependency>
                 <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>${spring.version}</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>com.sun.jersey.contribs</groupId>
                <artifactId>jersey-spring</artifactId>
                <version>${jersey.version}</version>
                <!-- jersey-spring uses spring 2.5, we want to use 3.x instead -->
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-core</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-web</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-beans</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-context</artifactId>
                    </exclusion>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aop</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
    
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
            </dependency>
    
    
            <dependency>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-json</artifactId>
                <version>${jersey.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.hsqldb</groupId>
                <artifactId>hsqldb</artifactId>
                <version>${org.hsqldb.version}</version>
            </dependency>
    
            <dependency>
                <groupId>commons-dbcp</groupId>
                <artifactId>commons-dbcp</artifactId>
                <version>${commons-dbcp.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-entitymanager</artifactId>
                <version>${org.hibernate.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${org.slf4j.version}</version>
            </dependency>
    
            <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.hibernate.common</groupId>
                <artifactId>hibernate-commons-annotations</artifactId>
                <version>${org.hibernate.version}</version>
            </dependency>-->
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-test</artifactId>
                <version>${spring.version}</version>
                <scope>test</scope>
            </dependency>
    
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>${junit.version}</version>
                <scope>test</scope>
            </dependency>
    
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <version>1.4.187</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${org.hibernate.version}</version>
        </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-webmvc</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
        </dependencies>
    
    </project>
    

1 个答案:

答案 0 :(得分:0)

在web.xml中,您的servlet定义缺少一个用于加载spring配置文件的init-param。

<servlet>
    <servlet-name>kuriculo</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
         <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/kuriculo-servlet.xml</param-value>
    </init-param>    
<load-on-startup>1</load-on-startup>
</servlet>

还删除url-pattern“* .jsp”并替换为“/ *”

<servlet-mapping>
    <servlet-name>kuriculo</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>