title: Handle multiple request in servlet and provide correct response to each request
body: <p>I m working on a JSP project(not using any framework). I came to a point where I m not able to make out the cause of the problem. 
  Implementation logic:
  When a requests is send to servlet it call a function A to get the dynamic content from the database and pass it back to the client from where the request came.</p>
  
  <p>Issue:
  When multiple request comes to servlet, they fetch's the data from function A(It get the form details from the database) and pass the data to wrong client. SO in client machine wrong form draws.</p>
  
  <p>How can handle request and response when multiple clients are involved. What can be the best practice to solve this issue. After searching internet I got singleton pattern and proxy class will help to resolve this issue ....Anyone have any idea please help me resolve this.</p>
  
  <pre><code>`// Getting value in jsp page
  String val = request.getParameter("mod_value");
  //calling function to get values from database
  List&lt;DrawForm&gt; dataModel = QueryFunction.getPageDetails(val);
  // Using this dataModel displaying the form
  for(int i=0;i&lt;dataModel.size();i++){
  //Display form
  }`
  
  
  
  
  
  //QueryFunction Class
  public class QueryFunction{
  public static Connection connect = null;
  public static CallableStatement statement = null;
  public static ResultSet rset = null;
  
  public static synchronized List&lt;DrawForm&gt; getPageDetails(String obj){
  
      List&lt;DrawForm&gt; dataModel = new ArrayList&lt;&gt;();
  
      try
      {   
          connect = DbConnection.GetConnection();
          statement = (CallableStatement)connect.prepareCall("{call 
          Get_form_template(?)}");
          statement.setString(1, obj);
          rset  = statement.executeQuery();
          while(rset.next()){
            DrawForm form = new DrawForm();
            // getting values in the array model
            dataModel.add(form);
          }                       
      }catch (Exception e) {
          e.printStackTrace();
      }finally {
          close();
      }       
      return dataModel;
  }
  private static void close() {
      if (connect != null) {
           try {
              connect.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  
       if (rset != null) {
           try {
               rset.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  
       if (statement != null) {
           try {
               statement.close();
          } catch (SQLException e) {
              e.printStackTrace();
          }
      }
  }
  
  
  }
  </code></pre>