Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 加载索引或第一页时出现HTTP状态404_Java_Spring_Spring Mvc_Servlets - Fatal编程技术网

Java 加载索引或第一页时出现HTTP状态404

Java 加载索引或第一页时出现HTTP状态404,java,spring,spring-mvc,servlets,Java,Spring,Spring Mvc,Servlets,我是春季MVC的新手。我正在开发我的第一个项目。如果我运行我的项目,会得到一个错误HTTP状态404。没有部署错误 我的web.xml如下所示 <?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001

我是春季MVC的新手。我正在开发我的第一个项目。如果我运行我的项目,会得到一个错误HTTP状态404。没有部署错误

我的web.xml如下所示

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" 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">

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

    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>

</web-app>

上下文配置位置
/WEB-INF/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
调度员
org.springframework.web.servlet.DispatcherServlet
1.
调度员
/
30
还有我的调度器servlet

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.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
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd ">

    <bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
    <mvc:annotation-driven />
    <mvc:view-controller path="/" view-name="view/index" />
    <context:component-scan base-package="com.innovaturelabs.multicast.controller" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
    </context:component-scan>
    <bean id="viewResolver"
         class="org.springframework.web.servlet.view.InternalResourceViewResolver"
         p:prefix="/WEB-INF/"
         p:suffix=".html">

    </bean>
</beans>

应用程序servlet是

<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?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:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd">

    <bean id="propertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
          p:location="/WEB-INF/Properties/Database.properties" />

    <util:properties id="hibernateProperties" location="/WEB-INF/Properties/Hibernate.properties" />

    <bean id="dataSource"
          class="org.apache.tomcat.jdbc.pool.DataSource"
          p:driverClassName="${database.driver}"
          p:url="${database.url}"
          p:username="${database.user}"
          p:password="${database.password}"
          p:testWhileIdle="true"
          p:validationQuery="SELECT 1" />


    <bean id="UserDao" class="com.innovaturelabs.multicast.dao.UserDao" />
    <bean id="sessionFactory"
      class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"
      p:dataSource-ref="dataSource"
      p:packagesToScan="com.innovaturelabs.spring.web.entity"
      p:hibernateProperties-ref="hibernateProperties" />

</beans>

只要将dispatcher servlet映射到“/”位置,所有请求都可以通过它

<context:component-scan base-package="com.innovaturelabs.multicast.controller" use-default-filters="false">
    <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
另一件事是,您应该将jsp文件与
InternalResourceViewResolver
一起使用,而不是使用html

   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
         p:prefix="/WEB-INF/"
         p:suffix=".jsp">
    </bean>


Html文件应该位于静态文件夹中,并由mvc映射:resource tag
404是一个客户端错误-“我找不到该页面”您在访问哪个url时运行什么上下文?访问日志怎么说?html文件放在WEB-INF/view/index.html中。tomcat日志不会产生任何错误消息您的JAR文件名是什么,您可以发布Maven POM吗?您使用什么url尝试访问它??你的回答是不够的
<mvc:resources mapping="/resources/**"
               location="/resources/html/"
<mvc:resources mapping="/resources/**"
               location="/resources/html/"