title: retrieve data from database table and display it in atable with html
body: <p>i am a beginer and am currently working on my final school project which require retrieving data from a database table and displaying the datas in an html page. i have searched alot but still no progress. i was linked to this site through google, i saw a format and i try to do the same thing but after running the code i get this error</p>
  
  <p><strong>Exception report</strong></p>
  
  <pre><code>message An exception occurred processing JSP page /crimeinfo.jsp at line 32 description The server encountered an internal error that prevented it from fulfilling this request.
  </code></pre>
  
  <p><strong>exception</strong></p>
  
  <pre><code>org.apache.jasper.JasperException: An exception occurred processing JSP page /crimeinfo.jsp at line 32
  29:     
  30:     
  31:     &lt;%List &lt;String&gt; data =(List)request.getAttribute("data");
  32:     Iterator &lt;String&gt; itr = data.iterator() ;
  33:     for (itr = data.iterator();
  34:     itr.hasNext();)
  35:     {%&gt;
  </code></pre>
  
  <p>please i need help. i dont known what else to do. thnks...</p>
  
  <p><strong>viewcrime.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!--web.xml code--&gt;
  &lt;servlet&gt;
  &lt;servlet-name&gt;viewcrimereport&lt;/servlet-name&gt;
  &lt;servlet-class&gt;viewcrimereport&lt;/servlet-class&gt;
  &lt;servlet-mapping&gt;
  &lt;servlet-name&gt;viewcrimereport&lt;/servlet-name&gt;
  &lt;url-pattern&gt;viewcrimereport&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;&lt;/servlet&gt;
  </code></pre>
  
  <p><strong>viewcrimereport.java</strong></p>
  
  <pre><code>public class viewcrimereport extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
       private ServletConfig config;
       String page = "crimeinfo.jsp";
       public void init(ServletConfig config)
           throws ServletException{
           this.config = config; }
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      PrintWriter out=response.getWriter();
      response.setContentType("text/html");
      Connection conn = null;
      String url = "jdbc:mysql://localhost/citycrime";
      String userName = "root";
      String passw = "jids";
      PreparedStatement pst = null;
      ResultSet rs;
      ArrayList&lt;String&gt; datalist = new ArrayList&lt;String&gt;();
      try{    
              int i=0;
      Class.forName("com.mysql.jdbc.Driver").newInstance();
          conn = DriverManager.getConnection(url, userName, passw);
          pst = conn.prepareStatement("");
      String sql ="select suspectname,suspectaliases,suspectht,suspectgender,features,crimeaddress,crimetype,caseno,casestatus from crimereport";
          pst.executeQuery(sql);
          rs = pst.getResultSet();
          while(rs.next()){
              datalist.add(rs.getString("suspectname"));
              datalist.add(rs.getString("suspectaliases"));
              datalist.add(rs.getString("suspectht"));
              datalist.add(rs.getString("suspectgender"));
              datalist.add(rs.getString("features"));
              datalist.add(rs.getString("crimeaddress"));
              datalist.add(rs.getString("crimetype"));
              datalist.add(rs.getString("caseno"));
              datalist.add(rs.getString("casestatus"));}
          rs.close();pst.close(); }
      catch(Exception e){System.out.println("Exception is;"+e);}
      request.setAttribute("data",datalist);
      RequestDispatcher dispatcher = request.getRequestDispatcher(page);
      if (dispatcher != null){
          dispatcher.forward(request, response);
      }
          }
  }    
  </code></pre>
  
  <p><strong>crimeinfo.jsp</strong></p>
  
  <pre><code>&lt;%@ page language="java" import="java.sql.*" import="java.util.*" 
  contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4
  /loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Crime Report&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;table border="1" with="600"&gt;
      &lt;tr&gt;&lt;td&gt;&lt;tb&gt;&lt;td&gt;SuspectName&lt;/td&gt;&lt;/b&gt;
      &lt;td&gt;&lt;tb&gt;SuspectAlias&lt;/b&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;suspectaliases&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;Height&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;suspectht&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;Gender&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;suspectgender&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;Features&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;features&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;Address&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;crimeaddress&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;CrimeType&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;crimetype&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;CaseNumber&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;caseno&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;Status&lt;/tb&gt;&lt;/td&gt;
      &lt;td&gt;&lt;tb&gt;casestatus&lt;/tb&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;% Iterator &lt;String&gt; itr;%&gt;
      &lt;%List data =(List)request.getAttribute("datalist");
      for (itr = data.iterator();
      itr.hasNext();){%&gt;&lt;tr&gt;
      &lt;%String s =(String)itr.next(); %&gt;
      &lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
          &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
          &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
  &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;
      &lt;tr&gt;&lt;td&gt;&lt;%=itr.next()%&gt;&gt;&lt;/td&gt;&lt;/tr&gt;&lt;%} %&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>