【发布时间】: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 在服务器上运行应用程序。