контекстное имя URL зависит от вашего военного имени.пожалуйста, проверьте ваше контекстное имя в лог-файлах tomcat (ваш сервер).
package com.test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HelloWorldServlet
*/
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloWorldServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
PrintWriter pw = response.getWriter();
pw.print("Hello web world!!");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
<servlet>
<servlet-name>Hello Web Servlet</servlet-name>
<servlet-class>com.test.HelloWorldServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello Web Servlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>