我的应用程序已正确部署,但出现404错误。
无法找到正在发生的事情。
在这种部署方式下,将我的webapp文件夹指向计算机中的位置。

使用的网址:


本地主机:8080 / studentspringmvc /


web.xml

  <?xml version="1.0" encoding="UTF-8"?>
  <web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 <display-name>Spring MVC Application</display-name>

 <context-param>
     <param-name>contextConfigLocations</param-name>
     <param-value>classpath*:applicationContext.xml</param-value>
 </context-param>


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

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

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

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>


现在我在conf / Catalina / localhost文件夹中添加了studentspringmvc.xml作为

studentspringmvc.xml

<Context path="/studentspringmvc"
  docBase="/home/shoaib/Documents/myprograms/studentspringmvc/src/main/webapp"
 reloadable="true"
/>


无法找到为什么不加载index.html的原因。

最佳答案

您的调度程序servlet映射到/。这意味着每个URL都映射到该servlet(包括index.html)。为了确保仍然提供静态文件,您需要按照the documentation中的说明启用默认的servlet处理程序:

<mvc:default-servlet-handler/>

关于java - 适用于Spring应用程序的Tomcat 6的404错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21760201/

10-11 20:49
查看更多