title: how to display values in jsp through java class
body: <p>I have a database with tables and values. I want to fetch that data and display it in jsp page. Don't want to write query in jsp page, separate java class,creating java object values and then displaying it in select field in jsp. please help me...    </p>
  
  <p>here is my java class 
                  p</p>
  
  <pre><code>ublic class EmpBean {
                      public java.util.List dataList(){
                          ArrayList list=new ArrayList();
                          try{
                               Class.forName("driver");
                                     Connection con = DriverManager.getConnection("url", "user", "pwd");
                                     Statement st=con.createStatement();
                                     System.out.println("hiiiii");
                                     ResultSet rs=st.executeQuery("select * from employee");
                                     while(rs.next()){
                                         list.add(rs.getString("name"));
                                         list.add(rs.getString("address"));
                                         list.add(rs.getString("contactNo"));
                                         list.add(rs.getString("email"));
  
  
                          }
                                     System.out.println(rs.getString("contactNo"));
                          }
                          catch(Exception e){}
                          return   list;
  
                          }
  
                  }
  
  //and my jsp file
                  &lt;%@page language="java" import="java.util.*" %&gt;
                  &lt;html&gt;
                  &lt;body&gt; 
                  &lt;table border="1" width="303"&gt;
                  &lt;tr&gt;
                  &lt;td width="119"&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/td&gt;
  
                  &lt;/tr&gt;
                  &lt;%Iterator itr;%&gt;
                  &lt;%EmpBean p = new EmpBean();
                  List list= (List) p.dataList(); %&gt;
                  for (itr=list.iterator(); itr.hasNext(); ){
                  %&gt;
                  &lt;tr&gt;
                  &lt;select name="" id="" style="width: 150px;""&gt;
                                  &lt;option value="-1"&gt;&lt;%=itr.next()%&gt;&lt;/option&gt;
                  &lt;/select&gt;
  
                  &lt;/tr&gt;
                  &lt;%}%&gt;
                  &lt;/table&gt;
                  &lt;/body&gt;
                  &lt;/html&gt;
  </code></pre>