Я хочу попробовать создать Maven-проект для Servlet API.У меня есть созданный сервлет с именем HelloWorldServlet следующим образом:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HelloWorldServlet
*/
@WebServlet("/HelloWord")
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 {
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 {
System.out.println("do post method called");
}
}
Во время сборки проекта он выдает следующую ошибку:
ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Project_Work/Other_learn/eclipse_workspace_lear/servletapi/src/main/java/com/learn/servlet/HelloWorldServlet.java:[6,21] package javax.servlet does not exist
[ERROR] /C:/Project_Work/Other_learn/eclipse_workspace_lear/servletapi/src/main/java/com/learn/servlet/HelloWorldServlet.java:[7,32] package javax.servlet.annotation does not exist
[ERROR] /C:/Project_Work/Other_learn/eclipse_workspace_lear/servletapi/src/main/java/com/learn/servlet/HelloWorldServlet.java:[8,26] package javax.servlet.http does not exist
[ERROR] /C:/Project_Work/Other_learn/eclipse_workspace_lear/servletapi/src/main/java/com/learn/servlet/HelloWorldServlet.java:[9,26] package javax.servlet.http does not exist
[ERROR] /C:/Project_Work/Other_learn/eclipse_workspace_lear/servletapi/src/main/java/com/learn/servlet/HelloWorldServlet.java:[10,26] package javax.servlet.http does not exist
[ERROR] /C:/Project_Work/Other_learn/eclipse_workspace_lear/servletapi/src/main/java/com/learn/servlet/HelloWorldServlet.java:[16,40] cannot find symbol
symbol: class HttpServlet
Я добавил следующие файлы jarв пути сборки: javax.servlet-api-3.0.1.jar и servlet-api.jar
Поэтому я прошу вас, ребята, дать мне знать, чего мне здесь не хватает.Заранее спасибо.