我将在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>
为什么我会在404 not found
和http://localhost:8080/index.jsp
中获得http://localhost:8080/hello
?
我正在使用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
答案 0 :(得分:2)
然后,您的网络应用程序位于http://localhost:8080/EeTest1Web/hello和http://localhost:8080/EeTest1Web/(适用于http://localhost:8080/EeTest1Web/index.jsp)。日志消息中的相关部分是
已注册的网络上下文:/ EeTest1Web