【问题标题】:http status 404 hello.jsp (apache tomcat 6)http状态404 hello.jsp(apache tomcat 6)
【发布时间】:2015-04-12 10:16:01
【问题描述】:

我是使用 apache 和 spring 框架的新手,我一直在使用本教程进行学习:http://docs.spring.io/docs/Spring-MVC-step-by-step/part1.html 我创建了一个 .jsp 文件,但是我的浏览器告诉我“请求的资源不可用。”

.jsp 文件非常简单

<html>
  <head><title>Hello :: Spring Application</title></head>
  <body>
    <h1>Hello - Spring Application</h1>
    <p>Greetings.</p>
  </body>
</html>

输入 http://localhost:8080/project/hello.htm 会给我一个 404。 我的 web.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>

<web-app 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" >

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

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

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

</web-app>

知道如何解决这个问题吗?

【问题讨论】:

  • 您正在遵循 7 年前编写的指南。它甚至使用 Ant。你知道新的 Spring 文档吗:spring.io/docs

标签: spring apache jsp tomcat ant


【解决方案1】:

404 错误意味着请求的资源不在服务器中。 您的问题可能是

1. 没有正确匹配 hello.htm 到任何控制器

bean id="/hello.htm" class="foo.controller" 或

2. 你必须把你的 hello.jsp 和 index.jsp 一起放在 webcontent 文件夹中。不在 WEB-INF 文件夹中。参考教程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 2018-05-06
    • 2017-03-28
    • 2021-06-19
    • 2017-01-04
    • 2018-11-09
    • 2016-01-05
    相关资源
    最近更新 更多