【发布时间】: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 上看到索引页面?