我只是构建了HelloWorld servlet,并将其部署到webapps文件夹中,并启动了Tomcat服务器(服务器时间)。我确实看到该项目已在应用程序管理器控制台中列出,但是当我尝试达到终点时,它返回了404异常。
Java文件:
@WebServlet("/HelloWorld")
public class HelloWorld extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloWorld()
{
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter printWriter = response.getWriter();
printWriter.println("<h1>Hello World!</h1>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// TODO Auto-generated method stub
}
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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>HelloWorldServlet</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
日志:
INFO:部署Web应用程序目录 C:\ Users \ arrchana \ Downloads \ apache-tomcat-7.0.37 \ windows-x64 \ apache-tomcat-7.0.37 \ webapps \ HelloWorldServlet
2019年5月5日12:17:15 org.apache.catalina.startup.HostConfig deployDirectory
ScreenShot1:
截屏2:
服务器详细信息: Apache Tomcat / 7.0.37 1.8.0_201-b09 Oracle Corporation Windows 10 10.0
有人想念我吗?