简体   繁体   中英

Servlet 404 issue while deploying on tomcat

I am getting 404 error while trying to deploy a servlet project. I took the war file from Netbeans and copied it in the webapps folder inside the tomcat folder.

Code :

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>

If I comment the servlet mapping and servlet part in web.xml, I can see the index.html. After undoing, I see just 404 error page. Please let me know what could be the error? Also what Actually I am suppose to write in action part and url-pattern in the web.xml

Thanks in advance.

please try to do the following :

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

</form>

and please give me some feedback .

Hope that helps .

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

@MultipartConfig

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM