Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringMVC页面无绑定_Java_Spring_Spring Mvc - Fatal编程技术网

Java SpringMVC页面无绑定

Java SpringMVC页面无绑定,java,spring,spring-mvc,Java,Spring,Spring Mvc,我编写了一个非常简单的spring mvc示例,希望在第页显示“hello world”。但它失败了。它只是在页面中显示“${message}” 下面是我的代码和jsp。我犯了什么错误吗?还是我错过了什么?谢谢 代码: 爪哇: servlet.xml: <?xml version="1.0" encoding="GBK"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:

我编写了一个非常简单的spring mvc示例,希望在第页显示“hello world”。但它失败了。它只是在页面中显示“${message}”

下面是我的代码和jsp。我犯了什么错误吗?还是我错过了什么?谢谢

代码: 爪哇:

servlet.xml:

    <?xml version="1.0" encoding="GBK"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">


    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <props>
                <prop key="/home.htm">homepageController</prop>
            </props>
        </property>
    </bean>

    <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>  

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>


    <bean id="homepageController" class="com.sunjq.config.web.HomepageController"/>



</beans>

主页控制器
web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
    <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 web-app_2_4.xsd"
    version="2.4">

    <display-name>Archetype Created Web Application</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/serviceContext.xml
            /WEB-INF/daoContext.xml
        </param-value>
    </context-param>
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>


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

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


    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>*.htm</url-pattern>
    </servlet-mapping>



</web-app>

Web应用程序创建的原型
上下文配置位置
/WEB-INF/serviceContext.xml
/WEB-INF/daoContext.xml
org.springframework.web.context.ContextLoaderListener
appServlet
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
/WEB-INF/appServlet-servlet.xml
1.
appServlet
/
appServlet
*.htm
jsp页面:

  <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  

    <html>  
    <head>  
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
    <title>Homepage</title>  
    </head>  
    <body>  
    ${message}  
    </body>  
    </html> 

主页
${message}

我猜您没有启用jstl,这与spring mvc无关。
您需要:

  • 确保您的web容器安装了jstl
  • 在页面顶部添加以下内容

  • 下面的答案提供了有关此主题的良好信息
    我建议将其作为参考。

    失败的原因是什么?发布错误消息谢谢您的回复。错误是页面总是显示${message}而不是“hello world”。我将把页面源放在主题线程头中。谢谢您好,我只是添加了说明,但服务器上没有日志。
      <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
    
        <html>  
        <head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>Homepage</title>  
        </head>  
        <body>  
        ${message}  
        </body>  
        </html>