我的小项目使用一个包含员工数据(姓名、电话、电子邮件)的数据库表。它通过网络浏览器提供员工列表的前端管理(插入新闻员工,编辑当前,删除现有)。
每当我从 Eclipse 在 Tomcat 服务器上运行我的项目(以显示所有员工的列表)时,我都会收到以下错误:
java.lang.NullPointerException com.myproject.crud.EmployeesListServlet.doGet(EmployeesListServlet.java:24) javax.servlet.http.HttpServlet.service(HttpServlet.java:621) javax.servlet.http.HttpServlet.service(HttpServlet.java :722)
第 24 行:request.setAttribute("employeess", employeesRepo.listEmployeess());
雇员列表Servlet
package com.myproject.crud;
import java.io.IOException;
import javax.inject.Inject;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
@WebServlet("/employees/")
public class EmployeesListServlet extends HttpServlet {
@Inject @JDBC
private EmployeesRepository employeesRepo;
public EmployeesListServlet() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("employeess", employeesRepo.listEmployeess());
getServletContext().getRequestDispatcher("/WEB-INF/pages/employees-listing.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}