1

I have made two servlets Authenticate.java and Accept.java

Here's the doGet function of Authenticate.java

      PreparedStatement stmt = null;
      PrintWriter out=response.getWriter();

      response.setContentType("text/html");  
      response.setCharacterEncoding("UTF-8");  
      try{
          int cnt=0;
          Class.forName("com.ibm.db2.jcc.DB2Driver");
          Connection con= DriverManager.getConnection("jdbc:db2://localhost:50000/SSMS", "kiit", "kiit");
          con.setAutoCommit(false);
          String s=request.getParameter("userName");
          if(s==null){
              out.println("You Are Not Authorized");
              return;
          }
          stmt=con.prepareStatement("SELECT COMP_ID,NAME,CONTACT FROM COMPANYREG");

          ResultSet rs=stmt.executeQuery();
          while(rs.next()){
              cnt++;
              out.println("<form action='Accept' method='post'> <input type='text'  size='20' id='cmpid' value='"+rs.getString(1)+"'><br> Name :"+rs.getString(2)+"<br>Contact: "+rs.getString(3)+"<br><input type='submit' class='confirm' id='"+cnt+"' value='Approve'><br></form>");
          }

And Heres Accept.java

               String user=request.getParameter("cmpid");

      PrintWriter out=response.getWriter();
      response.setContentType("text/html");  
      response.setCharacterEncoding("UTF-8"); 
      out.println("user = "+user);
      try{
          String cid = null,pss = null,nam = null,add = null,sec = null,cnt = null,ema = null;
          Class.forName("com.ibm.db2.jcc.DB2Driver");
          Connection con= DriverManager.getConnection("jdbc:db2://localhost:50000/SSMS", "kiit", "kiit");

          stmt=con.prepareStatement("SELECT * FROM COMPANYREG WHERE COMP_ID = '"+user+"'");
          ResultSet rs=stmt.executeQuery();
          out.println("query1");
          while(rs.next()){
              out.println("query2");
              cid = rs.getString(1);
              pss=rs.getString(2);
              nam=rs.getString(3);
              add=rs.getString(4);
              sec=rs.getString(5);
              cnt=rs.getString(6);
              ema=rs.getString(7);

          }
          out.println("query3");
          stmt=con.prepareStatement("INSERT INTO COMPANY VALUES ('"+cid+"','"+pss+"','"+nam+"','"+add+"','"+sec+"',"+cnt+",'"+ema+"')");

          int numRowsChanged= stmt.executeUpdate();
          if(numRowsChanged==0) out.println("Some Error Encountered Please Re-enter Information values Correctly");
          else out.println("You Were Registered Successfully.You will be allowed to login once your details are verified. Thank You");

In the Accept.java class when i refer to variable "cmpid" using request.getParameter("cmpid");

it is returning null ...... Can anybody tell me what actually is the problem here??

1 Answer 1

1
out.println("<form action='Accept' method='post'> <input type='text'  size='20' id='cmpid' value='"+rs.getString(1)+"'><br> Name :"+rs.getString(2)+"<br>Contact: "+rs.getString(3)+"<br><input type='submit' class='confirm' id='"+cnt+"' value='Approve'><br></form>");

add name attribute in form as "name=cmpid"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.