title: HTTP Status 500 - java.lang.NullPointerException
body: <p>I am new in java , jsp an I'm trying to print some data from Mysql database using an index.jsp. As the title says I'm getting an exception. I have checked for this exception a lot. I saw some same posts here in Stackoverflow but they did't help me. Here is my code:</p>
  
  <p><strong>index.jsp :</strong></p>
  
  <pre><code>&lt;%@ page language="java" 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;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form action ="New_printer.jsp" method="get"&gt;
      &lt;input type ="submit" value="Proceed"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>New_printer.jsp :</strong></p>
  
  <pre><code>&lt;%@page import="java.util.ArrayList"%&gt;
  &lt;%@page import="java.sql.ResultSet"%&gt;
  &lt;%@ page language="java" 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;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;%@ page import="com.results.Printer" %&gt;
  
  &lt;%
  int i;
  ArrayList Rows = new ArrayList();
  
  Rows = (ArrayList) request.getAttribute("data");
  
  for(i=1; i&lt;Rows.size(); i++)
  {
      ArrayList row = new ArrayList();
  
      row = (ArrayList) Rows.get(i);
      for(int j=1; j&lt;4; j++)
      {
          String word =(String) row.get(j);
          out.print(word + " ");
      }
      out.println();  
  }
  
  %&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>Printer.java :</strong></p>
  
  <pre><code>package com.results;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.Statement;
  import java.util.ArrayList;
  import java.io.IOException;
  
  import javax.servlet.RequestDispatcher;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  public class Printer extends HttpServlet{
  
      private static Connection con = null;
      ResultSet rs;
  
  
  
      @Override
      protected void doGet(HttpServletRequest req, HttpServletResponse resp)
              throws ServletException, IOException {
  
          resp.setContentType("text/jsp");
  
          try
          {
              Class.forName("com.mysql.jdbc.Driver");
              con = DriverManager.getConnection("jdbc:mysql://localhost:3306/tst","root","1234");
              Statement stmt = con.createStatement();
              rs = stmt.executeQuery("select * from test_db.person");
  
              ArrayList Rows = new ArrayList();
  
              while(rs.next())
              {
                  ArrayList row =new ArrayList();
                  for(int i=1; i&lt;4; i++)
                  {
                      row.add(rs.getString(i));
                  }
                  Rows.add(row);
              }
  
              req.setAttribute("data", Rows);
              RequestDispatcher rqdp = getServletContext().getRequestDispatcher("/New_printer.jsp");
              rqdp.forward(req, resp);
  
          }
  
          catch(Exception e)
          {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p><strong>web.xml :</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"&gt;
    &lt;display-name&gt;Simple_Print&lt;/display-name&gt;
    &lt;!-- 
    &lt;servlet&gt;
      &lt;servlet-name&gt;printer&lt;/servlet-name&gt;
      &lt;servlet-class&gt;com.results.Printer&lt;/servlet-class&gt;
    &lt;/servlet&gt;
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;printer&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/index.jsp&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt; --&gt;
  
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>EXCEPTION</strong></p>
  
  <pre><code>HTTP Status 500 - java.lang.NullPointerException
  
  type Exception report
  
  message java.lang.NullPointerException
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  org.apache.jasper.JasperException: java.lang.NullPointerException
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:548)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:469)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  root cause
  
  java.lang.NullPointerException
      org.apache.jsp.New_005fprinter_jsp._jspService(New_005fprinter_jsp.java:123)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:431)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
      org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  note The full stack trace of the root cause is available in the Apache Tomcat/8.0.20 logs.
  </code></pre>
  
  <p>Can you help? Please I'm stack here for days.</p>