首页 > 解决方案 > 我在这个 JBOSS/Wildfly servlet 中的 URL 是什么?

问题描述

我正在尝试学习 Wildfly 开发。我正在使用 Francesco Marchioni 的书“Java EE 7 Development with WildFly”。我只是想让 Hello World servlet 工作,但是当我转到“ http://localhost:8080/hello/test ”时出现 404 错误。根据这本书,@WebServlet("/test")放弃了使用 web.xml 文件的要求。有没有人有任何想法?

这是文件Webcontent/WEB_INF/jboss-web-xml

<jboss-web>
    <context-root>/hello</context-root>
 </jboss-web> 

TestServlet.java

package com.packtpub.wflydevelopement.chapter2;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TestServlet
 */
@WebServlet("/test")
public class TestServlet extends HttpServlet {

    private static final String CONTENT_TYPE = "text/html;charset=UTF-8";
    private static final String MESSAGE = "<!DOCTYPE html><html>" + "<head><title>Hello!</title></head>"
        + "<body>Hello World WildFly</body>" + "</html>";

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        try (PrintWriter out = response.getWriter()) {
            out.println(MESSAGE);
        }
    }
}

也是启动日志的一部分。

0:42:58,166 INFO  [org.infinispan.factories.GlobalComponentRegistry] (MSC service thread 1-4) ISPN000128: Infinispan version: Infinispan 'Estrella Galicia' 9.3.1.Final
20:42:58,828 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 72) WFLYCLINF0002: Started client-mappings cache from ejb container
20:42:59,676 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 74) WFLYUT0021: Registered web context: '/hello' for server 'default-server'
20:42:59,693 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 42) WFLYSRV0010: Deployed "HelloWorld.war" (runtime-name : "HelloWorld.war")
20:42:59,904 INFO  [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
20:42:59,913 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
20:42:59,914 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
20:42:59,914 INFO  [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 14.0.1.Final (WildFly Core 6.0.2.Final) started in 27197ms - Started 405 of 590 services (326 services are lazy, passive or on-demand)

标签: eclipseurljakarta-eejbosswildfly

解决方案


推荐阅读