【问题标题】:Error 404 in Eclipse while running Servlets on Tomcat在 Tomcat 上运行 Servlet 时出现 Eclipse 中的错误 404
【发布时间】:2014-07-18 05:04:07
【问题描述】:

我正在尝试使用 Eclipse IDE 在 Apache Tomcat 上执行一个简单的 servlet。 servlet 本身正在执行,但是当我尝试调用将用户数据传递给 servlet 的 html 表单时,我收到错误 404。 我的方法不正确吗?

更新 1: 文件 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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>assign3_servlets</display-name>
  <welcome-file-list>
    <welcome-file>clientFile.html</welcome-file>
  </welcome-file-list>

  <servlet>
    <servlet-name>DbServlet</servlet-name>
    <servlet-class>com.appperfect.training.DbServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>DbServlet</servlet-name>
    <url-pattern>/DbServlet</url-pattern>
  </servlet-mapping>
</web-app>

文件clientFile.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JDBC - Servlets</title>
</head>
<body bgcolor="white">
<form action="DbServlet" method="post" >
<table>
<tr>
    <td>JDBC Driver</td>
    <td> <input type="text" id="jdbc_driver" size="30"> </td>
</tr>
<tr>
    <td>JDBC URL</td>
    <td><input type="text" id="jdbc_url" size="30"></td>
</tr>
<tr>
    <td>User Name</td>
    <td><input type="text" id="uname" size="30"></td>
</tr>
<tr>
    <td>Password</td>
    <td><input type="password" id="pass" size="30"></td>
</tr>
<tr>
    <td>Query</td>
    <td><input type="text" id="query" size="30"></td>
</tr>
<tr>
    <td></td>
    <td ><input type="submit" id="submit_query"></td>
</tr>
</table>
</form>
</body>
</html>

【问题讨论】:

  • 能否请您发布您的web.xml.html 包含表单的文件。
  • 您提出这个问题的方法不正确。你怎么知道“servlet 本身正在执行”?您正在访问什么 URL 以及您的 web.xml 文件中有什么内容?您是否真的在 Eclipse 中将 Web 应用程序添加到 Tomcat,并且您确定 Tomcat 实例已同步并且所有内容都已发布?
  • 当我在 tomcat 上运行 servlet 时,它会显示。 printWriter() 语句显示在服务器上。但是当我首先运行 html 文件时,出现错误 404。服务器已同步并正在运行。

标签: eclipse servlets tomcat7


【解决方案1】:

在正确完成每个映射后,我错误地将文件放在了错误的文件夹中。 现在一切正常。

【讨论】:

    猜你喜欢
    • 2013-05-29
    • 2014-04-30
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 2013-01-01
    • 2015-01-31
    • 2018-04-07
    • 1970-01-01
    相关资源
    最近更新 更多