Jsp/Servlet 你好世界 JBoss

Jsp/Servlet Hello World With JBoss

我要 运行 我的 jsp/ servlet 在 JBoss 应用程序服务器中。

这是我的 index.jsp 页面:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title> hello </title>
</head>
<body>
        Hello World
</body>
</html>

这是我的 servlet class:

public class HelloServlet extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

        PrintWriter out = res.getWriter();
        out.write("hello , world");
        out.close();
    }
}

web.xml配置:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <servlet>
        <servlet-name>helloServlet</servlet-name>
        <servlet-class>HelloServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>helloServlet</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>

</web-app>

为什么我在 http://localhost:8080/index.jsphttp://localhost:8080/hello 中得到 404 not found

我正在使用 Intellij IDEA。

(log没有错误)

更新

Connected to server
[2015-09-16 02:29:07,679] Artifact EeTest1:ear exploded: Artifact is being deployed, please wait...
02:29:07,912 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-1) WFLYSRV0027: Starting deployment of "EeTest1_ear_exploded.ear" (runtime-name: "EeTest1_ear_exploded.ear")
02:29:07,990 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-8) WFLYSRV0207: Starting subdeployment (runtime-name: "web.war")
02:29:08,502 INFO  [org.wildfly.extension.undertow] (ServerService Thread Pool -- 27) WFLYUT0021: Registered web context: /EeTest1Web
02:29:08,605 INFO  [org.jboss.as.server] (management-handler-thread - 2) WFLYSRV0010: Deployed "EeTest1_ear_exploded.ear" (runtime-name : "EeTest1_ear_exploded.ear")
[2015-09-16 02:29:08,651] Artifact EeTest1:ear exploded: Artifact is deployed successfully
[2015-09-16 02:29:08,652] Artifact EeTest1:ear exploded: Deploy took 972 milliseconds

然后您的 Web 应用程序可在 http://localhost:8080/EeTest1Web/hello and http://localhost:8080/EeTest1Web/ (for http://localhost:8080/EeTest1Web/index.jsp) 获得。您的日志消息中的相关部分是

Registered web context: /EeTest1Web