我在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>发布于 2019-01-14 18:46:28
首先检查您的web.xml (部署描述符)文件,确保其中定义了正确的xml schema,如果一切正常,则将注释更改为@WebServlet("/Test/*")
发布于 2019-01-16 13:34:14
我通过重新命名这个项目解决了这个问题。我的项目名称由两个单词和一个空格组成。“密码服务”。一旦我将项目重命名为"Server“,我就可以访问servlet。
https://stackoverflow.com/questions/54179630
复制相似问题