【问题标题】:Servlet 404 issue while deploying on tomcat在 tomcat 上部署时出现 Servlet 404 问题
【发布时间】:2014-03-01 12:13:08
【问题描述】:

我在尝试部署 servlet 项目时遇到 404 错误。我从 Netbeans 中获取了 war 文件,并将其复制到了 tomcat 文件夹内的 webapps 文件夹中。

代码:

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
   <servlet>
        <servlet-name>UploadServlet</servlet-name>
        <servlet-class>com.example.Upload</servlet-class>

   </servlet>
   <servlet-mapping>
        <servlet-name>UploadServlet</servlet-name>
        <url-pattern>/UploadFile/UploadServlet</url-pattern>
   </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

index.html:

    <!DOCTYPE html>
  <!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <title>File Uploading Form</title>
    </head>
    <body>
       <h3>File Upload:</h3>
        Select a file to upload: <br />
       <form action="UploadServlet" method="post"
                    enctype="multipart/form-data">
           <input type="file" name="file" />
           <br />
           <input type="submit" value="Upload File" />
     </form>
  </body>
</html>

如果我在 web.xml 中注释 servlet 映射和 servlet 部分,我可以看到 index.html。撤消后,我只看到 404 错误页面。 请让我知道可能是什么错误?还有什么实际上我想写在 web.xml 中的动作部分和 url-pattern

提前致谢。

【问题讨论】:

  • 发布您用于访问您的应用程序的网址
  • localhost:8080/UploadFile/UploadServlet 试试这个
  • 如果我在 servlet 中注释映射和类,为什么它会起作用。意味着我可以在 URL localhost:8080/UploadFile 上看到索引页面?

标签: java jsp servlets web.xml


【解决方案1】:

如果您使用 Servlet API 3.0,请尝试在您的 servlet 类上添加注释。

@MultipartConfig

【讨论】:

    【解决方案2】:

    请尝试执行以下操作:

    <form action="/UploadFile/UploadServlet" method="post"
                        enctype="multipart/form-data">
    ...
    
    </form>
    

    请给我一些反馈。

    希望有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-05
      • 2018-03-13
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多