title: how to return value from java class to Servlet in java
body: <p>I have java class LoginValidation and Servlet Login ,am passing values from servlet to java class,but am not getting return values..from servlet to java class...</p>
  
  <p>//normal java class LoginValidation</p>
  
  <pre><code>public class LoginValidation {
  
      String userid="";
      String password="";
      String que="";
      Connection dbConnection = null;
      PreparedStatement pst=null;
      ResultSet rs=null;
      String userid1="";
      String password1="";
      int pan1=0;
  
      public long valiDate(String userid ,String password){
  
  
          long flag = 0l; 
          this.password=password;
          this.userid=userid;
  
          dbConnection = JDBCConnection.getDBConnection();
          que="select * from shivu";
          try {
              pst = dbConnection.prepareStatement(que);
              rs=pst.executeQuery();
  
              while(rs.next()){
               userid1=rs.getString(3);
               password1=rs.getString(2);
               pan1=rs.getInt(8);
  
               if ((userid.equals(userid1)) &amp;&amp; (password.equals(password1))){
                      flag = pan1;    
  
               }else{
                   flag = 0;
  
               }   
               }
  
          } catch (SQLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
  
          return flag;
      }
  }
  </code></pre>
  
  <p>//Servlet Login</p>
  
  <pre><code>public class Login extends HttpServlet {
      private static final long serialVersionUID = 1L;
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          // TODO Auto-generated method stub
  
  
  
          String userid=request.getParameter("userid");
  
          String password=request.getParameter("password");
  
          LoginValidation lv=new LoginValidation();
  
          System.out.println("control flow");
  
          long i=lv.valiDate(userid,password);
  
          System.out.println(i);
  
          if(i&gt;=1){       
  
              System.out.println("control flow inside method call");
  
              HttpSession session = request.getSession();
  
              if (session != null)
                  session.setAttribute("pan", i);
  
              response.sendRedirect("welcome.jsp");
          }
          else
          {
  
              System.out.println("Username or Password incorrect");
              response.sendRedirect("login1.jsp");
          }
  
  
  
  
      }
  
  }
  </code></pre>