1 Reply Latest reply: Nov 22, 2013 3:59 AM by morellik RSS

    JSP page set Bean variables but give NullPointerException when Bean try to merge in the DB

    morellik

      I'm new to JSP but I've to use it to grab data coming from an external site, pass data to a Bean, write data in a DB and redirect the user to another page. Follow the JSP page.


      <%@page import="EJB.getResponse"%>
      <%
      long paymentID = Long.parseLong(request.getParameter("paymentid"));
      String responsecode = "9999";
      getResponse g = new getResponse();
      if (request.getParameter("result") != null &&  request.getParameter("result").equals("CANCELED")) {
      String result = request.getParameter("result");
      String  threedsecure = request.getParameter("threedsecure");
      g.setThreedsecure(threedsecure);
      responsecode = "8888";
      g.setResponsecode(responsecode);
      g.setPaymentId(paymentID);
      g.printData();
      } else if (request.getParameter("error") != null) {
       String error = request.getParameter("error");
       String errortext = request.getParameter("errortext");
       g.setError(error);
       g.setErrortext(errortext);
       responsecode = "7777";
       g.setResponsecode(responsecode);
       g.setPaymentId(paymentID);
       g.printData();
       } else {
      String result = request.getParameter("result");
      String auth = request.getParameter("auth");
      long ref = Long.parseLong(request.getParameter("ref"));
      long tranid = Long.parseLong(request.getParameter("tranid"));
      String trackid = request.getParameter("trackid");
      String udf1 = request.getParameter("udf1");
      responsecode = request.getParameter("responsecode");
      String udf3 = request.getParameter("udf3");
      
      g.setAuth(auth);
      g.setPaymentId(paymentID);
      g.setRef(ref);
      g.setResult(result);
      g.setTranid(tranid);
      g.setTrackid(trackid);
      g.setUdf1(udf1);
      g.setResponsecode(responsecode);
      g.setUdf3(udf3);
      g.printData();
      }
      
      out.println("redirect=" + "http://mysite/Workshop/result.jsp?paymentID=" + paymentID + "&responsecode=" + responsecode);
      
      %>
      
      

       

      This is the bean:


      @ManagedBean
      @RequestScoped
      public class getResponse implements Serializable {
      
      private Long paymentId;
      private String result;
      private String auth;
      private Long ref;
      private Long tranid;
      private String trackid;
      private String udf1;
      private String responsecode;
      private String host;
      private String udf3;
      private String error;
      private String errortext;
      private String threedsecure;
      @EJB
      private ParticipantDAO participantDAO;
      
      Participant user;
      
      public void printData() {
          if (!responsecode.equals("00") && !responsecode.equals("000") &&
                  !responsecode.equals("8888") && !responsecode.equals("7777")) {
              return;
          }
          System.out.println("paymentID: " + paymentId);
      
          if (responsecode.equals("00") || responsecode.equals("000")) {
              System.out.println("responsecode: " + responsecode);
              System.out.println("result: " + result);
              System.out.println("trackid: " + trackid);
              System.out.println("tranid: " + tranid);
              System.out.println("auth: " + auth);
              System.out.println("udf1: " + udf1);
              System.out.println("udf3: " + udf3);
              Date date = new Date();
              user = participantDAO.getByTrackid(trackid);
              user.setPayed(Boolean.TRUE);
              user.setPaymentAuth(auth);
              user.setPaymentCreditCard(udf3);
              user.setPaymentDate(date);
              user.setPaymentDetails(udf1);
              user.setPaymentID(paymentId);
              user.setPaymentResponseCode(responsecode);
              user.setPaymentTranid(tranid);
              user.setPaymentResult(result);
              participantDAO.modify(user);
          } else if (responsecode.equals("8888")) {
              System.out.println("threedsecure: " + threedsecure);
              System.out.println("result: " + result);
              System.out.println("CANCELED");
              user = participantDAO.getByPaymentId(paymentId);
              System.out.println(user.getEmail());
              if (user != null) {
                  System.out.println("Write Result in DB");
                  user.setPaymentResult("CANCELED");
                  participantDAO.modify(user);
              }
          } else if (responsecode.equals("7777")) {
              System.out.println("NON AUTENTICATA");
              user = participantDAO.getByPaymentId(paymentId);
              user.setPaymentResult("NO AUTHENTICATED");
              participantDAO.modify(user);
          }
      
      
          //user = participantDAO.getByEmail(principal);
      }
      
      

       

      On the console I see the prints but I receive the NullPointerException


      WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
       java.lang.NullPointerException
      at EJB.getResponse.printData(getResponse.java:72)
      at org.apache.jsp.notify_jsp._jspService(notify_jsp.java from :60)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
      at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
      at java.lang.Thread.run(Thread.java:662)
      
      

       

      Where I wrong?