【发布时间】:2019-06-08 07:55:21
【问题描述】:
我在 Eclipse 中创建了一个名为 TestWeb 的新动态 Web 项目。我在 WebContent 文件夹中添加了一个 index.html 并创建了一个 Web servlet,使该 servlet 在 /Test 中可用。
我可以通过http://localhost:8080/TestWeb 访问 index.html 文件,但是我无法通过http://localhost:8080/TestWeb/Test 访问 servlet。请帮忙。
这是 Servlet 的代码:
@WebServlet("/Test")
public class Test extends HttpServlet {
private static final long serialVersionUID = 1L;
public Test() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
}
这是我的 web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="4.0">
<display-name>TestWeb</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
【问题讨论】:
-
请分享您的 web.xml
-
我分享了 web.xml 文件。
-
我不是 JEE 开发人员,但可能包含您获得的信息而不是您期望的信息会对那些可以帮助您的人有所帮助。那么您是否收到任何 404 错误?是否有与之相关的日志/堆栈跟踪?
-
@Hendré 尝试将
@WebServlet("/Test")更改为@WebServlet("TestWeb/Test") -
@Pshemo 我收到一个没有堆栈跟踪的 404 错误。