首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使用Eclipse和Tomcat 9访问servlet

无法使用Eclipse和Tomcat 9访问servlet
EN

Stack Overflow用户
提问于 2019-01-14 18:25:02
回答 2查看 306关注 0票数 0

我在Eclipse中创建了一个名为TestWeb的新动态web项目。我在WebContent文件夹中添加了一个index.html,并创建了一个web servlet,使该servlet在/Test上可用。

我可以访问http://localhost:8080/TestWeb上的index.html文件,但是不能访问http://localhost:8080/TestWeb/Test上的servlet。请协助。

下面是Servlet的代码:

代码语言:javascript
复制
@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:

代码语言:javascript
复制
<?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>
EN

回答 2

Stack Overflow用户

发布于 2019-01-14 18:46:28

首先检查您的web.xml (部署描述符)文件,确保其中定义了正确的xml schema,如果一切正常,则将注释更改为@WebServlet("/Test/*")

票数 0
EN

Stack Overflow用户

发布于 2019-01-16 13:34:14

我通过重新命名这个项目解决了这个问题。我的项目名称由两个单词和一个空格组成。“密码服务”。一旦我将项目重命名为"Server“,我就可以访问servlet。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54179630

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档