java - Jsp/Servlet Hello World 与 JBoss

标签 java jsp servlets intellij-idea jboss

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

这是我的 index.jsp 页面:

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

这是我的 servlet 类:

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 。

(日志中没有错误)

更新

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

最佳答案

然后您的网络应用程序就可以在 http://localhost:8080/EeTest1Web/hello 上使用。和 http://localhost:8080/EeTest1Web/ (对于 http://localhost:8080/EeTest1Web/index.jsp )。您的日志消息中的相关部分是

Registered web context: /EeTest1Web

关于java - Jsp/Servlet Hello World 与 JBoss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32596188/

相关文章:

java - 限制从特定机器访问网站

java - JExcel 警告 : Could not add cell at A257 because it exceeds the maximum column limit'

java - JSP 登录注销使用 bean 的简单 Web 应用程序 - 当数据库中存在数据时返回 false

java - 在 ArrayList 中查找特定单词

java - 可运行的 jar 打开错误(计算器程序)

javascript - 无法执行在父 jsp div 标记内调用的子 html 的 onload()

java - JSP中如何对齐元素的输出?

Java ProcessBuilder 在传递参数时使用字符串中的句点而不是斜杠

java - 我如何编译包中的类,以便稍后使用 "java Program"(没有包名称)执行它们?

java - jsp 上没有打印任何内容来添加模型对象