这个JBOSS / Wildfly Servlet中的URL是什么?

时间:2019-02-19 05:05:17

标签: eclipse url java-ee jboss wildfly

我正在尝试学习Wildfly开发。我正在使用Francesco Marchioni的书“使用WildFly进行Java EE 7开发”。我只是想让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)

0 个答案:

没有答案