简体   繁体   English

servlet的标准包装器值[register]:servlet.service()抛出异常java.lang.nullpointerexception;

[英]standard wrapper value[register]:servlet.service() for servlet threw exception java.lang.nullpointerexception;

my program returns a null object value but i need to use the null object value for verification but because it is a servlet page and i have try block so whats happening the try catches the exception and throwing null point exception. 我的程序返回一个空对象值,但是我需要使用该空对象值进行验证,但是因为它是一个servlet页面,并且我有try块,所以try发生的事情捕获了异常并抛出了null点异常。

         public class login extends HttpServlet {
                protected void processRequest(HttpServletRequest request,                          HttpServletResponse response)
       throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    String pass="",value="",email_id="";
    DBObject doc;
    try (PrintWriter out = response.getWriter()) {
        a=request.getParameter("email");
        out.println(a);
        b=request.getParameter("password");
        out.println(b);
        MongoClient client = new MongoClient();
        DB db = client.getDB("smart");
        DBCollection coll = db.getCollection("register");
      // here when am get a email id from the user in "a"  variable it matches in the database and retrieve it if the user not in db means it have to displayed user not in database bt it showing a null pointer expection bt i need to process the null 
        doc = coll.findOne(new BasicDBObject("email_id", a));
        //obj=doc.toString();

        email_id=doc.get("email_id").toString();

        pass = doc.get("Password").toString();

         key=doc.get("Key").toString();
       //here is the problem
         if((doc.toString()) == null)
        {
           out.println("user not in db");
           System.out.println("user not  in db");

        }
   }

} }

Hi 你好
Did you handled the exception ? 您是否处理了例外? if yes why you didn't include that code? 如果是,为什么不包括该代码?
if No please put catch block there you have to check whether that doc is null or not if it is null print "user is not in db". 如果否,请在其中放置catch块,如果该文档为null,则必须检查该文档是否为null打印“用户不在数据库中”。

因为我发布了空指针异常,所以即使catch也不捕获它,但是我犯的错误是在响应对象提交后,我已经验证了它是否为null,所以当我检查doc对象是否为null或没有,它可以验证,但是我可以重定向到存在问题的下一页,已提交响应,因此在重定向到页面时也请进行此检查

暂无
暂无

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

相关问题 为什么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 严重:Servlet [package]的Servlet.service()在路径[/ portal]的上下文中引发了异常java.lang.NullPointerException - SEVERE: Servlet.service() for servlet [package] in context with path [/portal] 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 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 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 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]:PWC1406:servlet jsp的Servlet.service()抛出异常java.lang.NullPointerException - WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM