简体   繁体   English

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

[英]StandardWrapperValve[web.dbServlet]: Servlet.service() for servlet web.dbServlet threw exception java.lang.NullPointerException

I try to insert some information in the table, but get such an error (NullPointerException). 我尝试在表中插入一些信息,但出现这样的错误(NullPointerException)。 Maybe it causes of empty request, but I'm not sure. 也许这是导致请求为空的原因,但我不确定。

Here is a log with error: enter image description here 这是有错误的日志: 在此处输入图片描述

First Servlet: 第一个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");

}

The second one: 第二个:

@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");
}

Problem appears in this Servlet: 问题出现在此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();    
} 
}

At first impression i can say that maybe the first and second servlet are for a POST method so doing a doGet and trying to 'getParameter' you will get empty object and so throw a NullPointerException. 乍一看,我可以说也许第一个和第二个servlet是用于POST方法的,所以执行doGet并尝试“ getParameter”时,您将获得空对象,因此抛出NullPointerException。 Can you post something about your view? 您可以发表一些您的看法吗?

(I would comment but i can't yet) (我会发表评论,但我还不能)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 StandardWrapperValve [Jersey Web Application]:Servlet Jersey Web Application的Servlet.service()抛出异常java.lang.NullPointerException - StandardWrapperValve[Jersey Web Application]: Servlet.service() for servlet Jersey Web Application threw exception java.lang.NullPointerException 警告:StandardWrapperValve [jsp]:servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException glassfish - WARNING: StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException glassfish 警告:StandardWrapperValve [jsp]:PWC1406:servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException - WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException JSP NullPointer StandardWrapperValve[servlets. ]:用于 servlet servlet 的 Servlet.service()。 抛出异常 java.lang.NullPointerException - JSP NullPointer StandardWrapperValve[servlets. ]: Servlet.service() for servlet servlets. threw exception java.lang.NullPointerException java / jsf奇怪的错误:警告:StandardWrapperValve PWC1406:Servlet.service()...抛出异常java.lang.NullPointerException - java/jsf strange error: WARNING: StandardWrapperValve PWC1406: Servlet.service() … threw exception java.lang.NullPointerException 严重:Servlet [package]的Servlet.service()在路径[/ portal]的上下文中引发了异常java.lang.NullPointerException - SEVERE: Servlet.service() for servlet [package] in context with path [/portal] threw exception java.lang.NullPointerException servlet的标准包装器值[register]:servlet.service()抛出异常java.lang.nullpointerexception; - standard wrapper value[register]:servlet.service() for servlet threw exception java.lang.nullpointerexception; 为什么servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException? - Why Servlet.service() for servlet jsp threw exception java.lang.NullPointerException? Servlet默认的Servlet.service()抛出异常java.lang.NullPointerException - Servlet.service() for servlet default threw exception java.lang.NullPointerException Struts 2:SEVERE:Servlet默认的Servlet.service()抛出异常java.lang.NullPointerException - Struts 2: SEVERE: Servlet.service() for servlet default threw exception java.lang.NullPointerException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM