Java spring mvc预期输出

Java spring mvc预期输出,java,spring,jsp,spring-mvc,Java,Spring,Jsp,Spring Mvc,这是我的第一个spring mvc程序。该程序没有显示任何错误,但没有显示预期的输出。下面是代码 HelloContoller.java hello.jsp 在此处插入标题 消息:${Message} mvc-servlet.xml /WEB-INF/pages/ .jsp web.xml Web应用程序创建的原型 上下文配置位置 /WEB-INF/mvc-servlet.xml org.springframework.web.context.ContextLoaderListener

这是我的第一个spring mvc程序。该程序没有显示任何错误,但没有显示预期的输出。下面是代码

HelloContoller.java hello.jsp

在此处插入标题
消息:${Message}
mvc-servlet.xml

/WEB-INF/pages/
.jsp
web.xml

Web应用程序创建的原型
上下文配置位置
/WEB-INF/mvc-servlet.xml
org.springframework.web.context.ContextLoaderListener
mvc
org.springframework.web.servlet.DispatcherServlet
1.
mvc
/
我得到的结果是“Message:${Message}”,但我的输出应该是“Message:spring3mvcmhelloworld”。
因此,任何人都可以帮助我在程序中找到mitake。

您使用的是JSP 1.2的旧web.xml声明(使用DTD 2.3)。在这种情况下,您的EL指令-
${message}
-将不会呈现,除非您有意启用它,默认情况下它不会呈现。所以你有两个选择:

您可以使用JSP文件头中的页面指令
来启用EL表达式

或者,您可以将web.xml声明升级到架构版本:

<web-app id="AppName" 
         version="2.4" 
         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">

    ...

</web-app>

...

如果您没有理由使用JSP1.2,我推荐第二种选择。但是,任何一个都应该使您的EL指令正确呈现。

您如何访问此页面?您在浏览器中点击的URL是什么?
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <h1>Message : ${message}</h1>
</body>
</html>
<?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:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

    <context:component-scan base-package="com.controller" />
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>


    </bean>
</beans>
    <!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>/WEB-INF/mvc-servlet.xml</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>mvc</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>mvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
<web-app id="AppName" 
         version="2.4" 
         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">

    ...

</web-app>