Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用ApacheTomcat v7的Eclipse中的servlet中存在HTTP 404错误_Java_Tomcat_Servlets - Fatal编程技术网

Java 使用ApacheTomcat v7的Eclipse中的servlet中存在HTTP 404错误

Java 使用ApacheTomcat v7的Eclipse中的servlet中存在HTTP 404错误,java,tomcat,servlets,Java,Tomcat,Servlets,下面是我的jsp代码 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@page import="connection.*" %> <%@page import="java.sql.*" %> <!DOCTYPE html> <html> <head&g

下面是我的jsp代码

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@page import="connection.*" %> 
<%@page import="java.sql.*" %> 

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>VIEW REPORTS</title>
    </head>
    <body>
    <div align="center"><b>View Reports</b></div>
    <form action="GetRole" method="get">
    <p>Enter user id:
    <input type="text" name="userid"><br>
    <input type="submit" value="submit"><br>
    </form>
    Choose the type of report:
    <script type="text/javascript" src="list.js"></script>
    <select name="first1" id="firstselect" onchange="first()">

        <option>Select</option>
        <option value="NEFT">NEFT REPORTS</option>
        <option value="LOAN">LOAN REPORTS</option>
        <option value="TRAN">TRANSACTION REPORTS</option>
    </select>

    <script type="text/javascript"></script> 


    </body>
    </html>
以下是我的
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>Final_Bank</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>
      <servlet-name>GetRole</servlet-name>
      <servlet-class>GetRole</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>GetRole</servlet-name>
      <url-pattern>/GetRole</url-pattern>
    </servlet-mapping>
  </web-app>

最终清算银行
index.html
index.htm
index.jsp
default.html
default.htm
default.jsp
GetRole
GetRole
GetRole
/GetRole

请让我知道它为什么抛出404错误。我在网上搜索了相当长的一段时间以获得一个合适的分辨率,但没有一个解决方案对我有效。我在Eclipse中使用了ApacheTomcat服务器。

servlet位于包
所有包
中,因此
web.xml
文件中的映射应该是:

<servlet>
  <servlet-name>GetRole</servlet-name>
  <servlet-class>all_packages.GetRole</servlet-class>
</servlet>

假设您的tomcat在端口
8080

上运行,什么时候会发生错误?哪个网址?提交表格后?@andih,提交表格后是。提交后,url将出现:
http://localhost:8080/Final_Bank/GetRole?userid=wcw
能否在您的帖子中更新您的
web.xml
以表示您当前的本地版本。您是否检查了控制台,以确定在启动web应用程序时是否存在任何错误?您是否尝试过通过curl
curl-v等工具访问GetRole资源http://localhost:8080/Final_Bank/GetRole?userid=...
?Curl允许您查看请求/响应,还可以避免缓存问题。在eclipse中,清理模块工作目录可能会有所帮助。这可以在“服务器视图”中找到。@andih,感谢您的宝贵意见。最后,我决定添加ServletURL模式和servlet类,如下面给出的答案所示。我的问题是url模式。但是现在我又遇到了另一个错误,因为我的servlet在“preparedStatement”行中提供了输入之后抛出了“Nullpointer异常”。如果这是我在WebContainer/WebApplication/Tomcat启动期间预期出现
ClassNotFoundException
的原因,那么在这次修改之后,我仍然会遇到404错误。
<servlet>
  <servlet-name>GetRole</servlet-name>
  <servlet-class>all_packages.GetRole</servlet-class>
</servlet>
http://localhost:8080/myapp/sample.jsp