StandardWrapperValve [web.dbServlet]:servlet web.dbServlet的Servlet.service()抛出了异常java.lang.NullPointerException

时间:2017-01-31 14:41:08

标签: java servlets glassfish hsqldb

我尝试在表中插入一些信息,但是会出现这样的错误(NullPointerException)。也许它导致空的请求,但我不确定。

这是一个有错误的日志: enter image description here

First Servlet:

@WebServlet("/clientServlet")
public class clientServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

protected void doGet(HttpServletRequest request,
                     HttpServletResponse response)
        throws ServletException, IOException {

    Client client = new Client();
    client.setName(request.getParameter("name"));
    client.setSurname(request.getParameter("surname"));
    HttpSession session = request.getSession();
    session.setAttribute(sessionKey.client, client);
    response.sendRedirect("addTour.html");

}

第二个:

@WebServlet("/tourServlet")
public class tourServlet extends HttpServlet{

private static final long serialVersionUID = 1L;

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    HttpSession session = request.getSession();

    Tour tour = new Tour();
    tour.setCountryTo(request.getParameter("countryTo"));
    tour.setAmountOfDays(request.getParameter("amountOfDays"));
    session.setAttribute(sessionKey.tour, tour);
    response.sendRedirect("final.jsp");
}

此Servlet中出现问题:

@WebServlet("/dbServlet")
public class dbServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

public dbServlet() {
    super();
}

 protected void doGet(HttpServletRequest request, HttpServletResponse   response) throws ServletException, IOException { 
    try {
        IRepositoryCatalog catalog = new  RepositoryCatalog("jdbc:hsqldb:hsql://localhost/workdb");
        HttpSession session = request.getSession();
        Client client = (Client) session.getAttribute(sessionKey.client);
        Tour tour = (Tour) session.getAttribute(sessionKey.tour);
        catalog.Clients().add(client);
        catalog.saveAndClose();

        catalog.Tours().add(tour);
        catalog.saveAndClose();
        catalog.saveAndClose();

    } catch (SQLException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException a) {
        a.printStackTrace();    
} 
}

1 个答案:

答案 0 :(得分:0)

第一印象我可以说第一个和第二个servlet可能是一个POST方法所以做一个doGet并尝试'getParameter'你会得到一个空对象,所以抛出一个NullPointerException。你能发表一些关于你观点的文章吗?

(我会评论,但我还不能)