Я не могу получить свой индексный файл. html файл для вызова моего getEmployees. java сервлет, и я не знаю, почему он не работает, потому что я использую шаблон URL сервлетов. Затем метод getEmployees должен перенаправить управление в файл listEmployees. jsp.
Ошибка возникает при нажатии гиперссылки на странице html;
Состояние HTTP 404 - / getEmployees
тип Отчет о состоянии
message / getEmployees
описание Запрошенный ресурс недоступен.
Apache Tomcat / 8.0.3
И код;
<html>
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div></div>
<a href="/getEmployees"> View Employees </a>
</body>
</html>
@WebServlet(urlPatterns = {"/getEmployees"})
public class getEmployees extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
Employee E1 = new Employee("Rick Astley", 1234);
Address A1 = new Address("63 Elm Street");
Position P1 = new Position("Gentleman",20000);
E1.setAddress(A1);
E1.setPosition(P1);
Employee E2 = new Employee("Jesus", 5555);
Address A2 = new Address("desert");
Position P2 = new Position("Full-time son of God",0);
E1.setAddress(A2);
E1.setPosition(P2);
List<Employee> storage = new ArrayList<Employee>();
storage.add(E1);
storage.add(E2);
HttpSession session = request.getSession();
session.setAttribute("List", storage);
RequestDispatcher dis=request.getRequestDispatcher("listEmployees.jsp");
dis.forward(request,response);
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet listEmployees</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet listEmployees at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}