【问题标题】:Servlet gives 404 (Eclipse + Tomcat)Servlet 给出 404 (Eclipse + Tomcat)
【发布时间】:2012-12-30 12:58:41
【问题描述】:

我正在学习 Lars Vogel 在 http://www.vogella.com/articles/EclipseWTP/article.html 上的教程,但遇到了 404 错误。 于是我在Eclipse中创建了一个Dynamic Web Project,然后按照教程创建了FileDao.java和FileCounter.java。 Eclipse 为我生成了一个 web.xml 文件,这里是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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" id="WebApp_ID" version="2.5">
  <display-name>de.vogella.wtp.filecounter</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <description></description>
    <display-name>FileCounter</display-name>
    <servlet-name>FileCounter</servlet-name>
    <servlet-class>de.vogella.wtp.filecounter.servlets.FileCounter</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FileCounter</servlet-name>
    <url-pattern>/FileCounter</url-pattern>
  </servlet-mapping>
</web-app>

我使用的是 Tomcat 6.0,并在创建项目时选择了 Dynamic web module version 2.5。

【问题讨论】:

  • 如何访问 Web 应用程序 (URL)?日志中有任何内容吗?
  • servlet类的源码是什么?你部署了webapp吗?你为 webapp 选择了什么上下文路径?您在浏览器的地址栏中输入了什么 URL 来调用 servlet?
  • 现在我进行了更多搜索,结果如下:我将 url-pattern 从 /FileCounter 更改为 *.do,现在它可以正常工作了!你能解释一下我做了什么吗?关于cmets:我通过浏览器访问Web应用程序,输入localhost:8080/de.vogella.wtp.filecounter/FileCounter。除此之外,我不知道在哪里可以找到日志、如何部署 web 应用程序以及上下文路径是什么——我只是通过 Eclipse 在服务器上运行应用程序。

标签: java eclipse tomcat


【解决方案1】:

您要访问哪个 URL? ...尝试

http://localhost:8080/<Include Your Project Name>/FileCounter

【讨论】:

  • 这就是我正在做的事情!我的项目名称是 de.vogella.wtp.filecounter,我正在访问 localhost:8080/de.vogella.wtp.filecounter/FileCounter
  • 首先检查你的应用是否已经部署在Tomcat的WebApps文件夹中。
  • 我猜测战争的名称与项目名称不同。检查 Tomcat 的 webapp 文件夹中的文件夹名称。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
  • 2011-02-08
  • 2018-04-07
  • 2013-05-29
  • 1970-01-01
相关资源
最近更新 更多