title: Converting array of HahMap into json object in servlet and display it in jsp page
body: <p>I want to fetch all table rows and add them into array of hashmap then convert them into json object to send to jsp page using ajax and jquery. I'm having problem in displaying the contents in jsp page. 
  I have managed to write the below code and need help to correct/improve it and I'm confused how to display it in jsp page. I'm a beginner in jquery and json.</p>
  
  <pre><code>   try {
         String res = request.getParameter("hello");
         String user = "";
         String pass = "";
         String port = "";
         String dbname = "";
         String host = "";
         String driver = "oracle.dbc.driver.OracleDriver";
         Connection con;
         PreparedStatement ps;
         ResultSet rs;
         String json = null;
         String url = "jdbc:oracle:thin:@"+host+":"+port+":"+dbname;
  
         Map&lt;String,String&gt; map = new HashMap&lt;String,String&gt;();
         List&lt;Map&lt;String,String&gt;&gt; list = new ArrayList&lt;Map&lt;String,String&gt;&gt;();
  
         try{
              Class.forName(driver).newInstance();
              con = DriverManager.getConnection(url,user,pass);
              ps = con.prepareStatement("select * from employee");
  
              rs = ps.executeQuery();
              while(rs.next()){
                  map.put("name", rs.getString(1));
                  map.put("id", rs.getString(2));
                  map.put("salary",rs.getString(3));
                  list.add(map);
              }                
              json = new Gson().toJson(list);
              response.setContentType("application/json");
              response.setCharacterEncoding("UTF-8");
              response.getWriter().write(json);
         }catch(Exception e){               
         }
  
  
      } finally {            
          out.close();
      }
  </code></pre>
  
  <p>index.jsp</p>
  
  <pre><code>&lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          $(document).ready(function(){
              $("#push").click(function(){
                 var value = $("#t").val();
                 $.post('jsonServlet',{hello:value},function(data){
  
               //     ??
                //    ??
                //    ??
  
                 });
              });            
          });
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body  style="position: absolute;min-height: 700px;min-width: 1300px"&gt;
      &lt;form&gt;
          &lt;input type="button" value="PushMe" id="push"&gt;
          &lt;input type="text" id="t" value="my data"&gt;
          &lt;div style="position: absolute;height: 50%;width: 60%;" id="myDiv"&gt;
  
          &lt;/div&gt;
      &lt;/form&gt;        
  &lt;/body&gt;
  </code></pre>
  
  <p>Need help in jsp page to display the contents of hash map in div...
  Later I will change the div with text boxes to store individual column values so that user can modify the contents of table and again update the table rows.</p>
  
  <p>Need help</p>