404 error for tomcat 6 for spring application

狂风中的少年 提交于 2019-12-13 04:26:13

问题


My app is deployed properly but getting 404 error. Unable to find what is happening. In this deployed means pointing my webapp folder to location in computer.

URL used :

localhost: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>

Now I have added studentspringmvc.xml in conf/Catalina/localhost folder as

studentspringmvc.xml

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

Unable to find why atleast index.html is not loading.


回答1:


Your dispatcher servlet is mapped to /. This means that every URL is mapped to this servlet (index.html included). To make sure static files are still served, you need to enable the default servlet handler as explained in the documentation:

<mvc:default-servlet-handler/>


来源:https://stackoverflow.com/questions/21760201/404-error-for-tomcat-6-for-spring-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!