我有一个包含以下内容的战争文件:
META-INF
|___MANIFEST.MF
WEB-INF
|___web.xml
|___classes
|____servlet
|____StarterServlet.class
我的 web.xml 看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>WAR</display-name>
<servlet>
<display-name>Starter Servlet</display-name>
<servlet-name>StarterServlet</servlet-name>
<servlet-class>servlet.StarterServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>StarterServlet</servlet-name>
<url-pattern>/starter</url-pattern>
</servlet-mapping>
</web-app>
我的 servlet 代码是:
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class StarterServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@Override
public void init(ServletConfig servletConfiguration) throws ServletException {
super.init(servletConfiguration);
System.out.println("SERVLET STARTED!");
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("DOGET!");
PrintWriter printWriter = response.getWriter();
printWriter.println("Hello world");
}
}
此外,我的运行时名称是:“war”,所以我将使用以下 URL 查找我的上下文根:
http://localhost:8080/war/starter。
主要问题是我的 servlet 没有被初始化,我在 jboss 日志文件上看不到任何痕迹,尽管我的战争被正确部署。
我哪里做错了?
谢谢
MMTTMM
三国纷争
相关分类