【问题标题】:404 error for tomcat 6 for spring application春季应用程序的tomcat 6出现404错误
【发布时间】:2014-03-12 16:23:53
【问题描述】:

我的应用已正确部署,但出现 404 错误。 无法找到正在发生的事情。 在此已部署意味着将我的 webapp 文件夹指向计算机中的位置。

使用的网址:

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>

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

studentspringmvc.xml

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

无法找到至少 index.html 未加载的原因。

【问题讨论】:

  • 你检查过tomcat日志吗?它说什么?
  • 没有错误部署成功。可能是我触发了错误的 url 或提到了错误的 url 模式。我已经上传了显示 studentspringmvc true 的新图片。
  • 这个 applicationContext.xml 文件到底在哪里?
  • WEB-INF .....没问题。它找到了 applicationContext.xml 文件和所有文件。
  • 你是在eclipse里面的tomcat上部署的吗?如果是,那么您的 Context 应该包含 source="org.eclipse.jst.jee.server:PROJECTNAME"

标签: java spring tomcat6 web.xml


【解决方案1】:

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

<mvc:default-servlet-handler/>

【讨论】:

  • 但是添加这一行我的控制权并没有进入控制器。
猜你喜欢
  • 2014-04-23
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-27
  • 1970-01-01
  • 2021-07-14
  • 2021-05-30
相关资源
最近更新 更多