简体   繁体   English

java servlet空点异常

[英]java servlet Null point exception

I keep getting this a java.lang.null pointer exception, any help or suggestions would be much appreciated, I thought by putting in the if statement i would get rid of the errors so i have no idea what is wrong 我一直在收到这个java.lang.null指针异常,我非常感谢任何帮助或建议,我想通过放入if语句可以摆脱错误,所以我不知道哪里出了问题

  StandardWrapperValve[UserManagementServlet]: Servlet.service() for 
  servlet UserManagementServlet threw exception
  java.lang.NullPointerException
      at com.bsapp.servlets.UserManagementServlet.processRequest(UserManagementServlet.java:40)
at com.bsapp.servlets.UserManagementServlet.doGet(UserManagementServlet.java:104)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 

The jsp file is jsp文件是

           </div>
            <form action="<c:url value='/UserManagement?action=listConfirm'/>">
            <!--<input type="text" name="action">-->
            <button class ="btn btn-large" type ="submit">USERS</button>
            </form>
            </div>

and the servlet is servlet是

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

    String action = request.getParameter("action");

    if (action.equals("list")) {
        doUserListing(request, response);
    }
    if (action.equals("add")) {
        addNewUser(request, response);
    } else{
         out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet SearchServlet</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Well Shit</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

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

    UserDAO userDAO = new UserDAO();
    Vector<User> allUsersVect = userDAO.getAllUsers();

    request.getSession(true).setAttribute(IConstants.SESSION_KEY_ALL_USERS, allUsersVect);

    RequestDispatcher rd = request.getRequestDispatcher("/user-listing.jsp");
    rd.forward(request, response);

}

Firstly, you should provide what line is 40. The error is either that request or action is null as far as I can tell with the limited information you provided. 首先,您应该提供40行。根据我提供的有限信息,错误可能是requestaction为空。 Try adding 尝试添加

if (action == null)
    return;

Make sure to replace return; 确保更换return; with any error processing you need to execute. 与您需要执行的任何错误处理。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM