[英]Servlet 404 issue while deploying on tomcat
尝试部署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的内容
提前致谢。
请尝试执行以下操作:
<form action="/UploadFile/UploadServlet" method="post"
enctype="multipart/form-data">
...
</form>
请给我一些反馈。
希望能有所帮助。
如果使用Servlet API 3.0,请尝试在Servlet类上添加注释。
@MultipartConfig
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.