title: Getting list of strings from servlet to jsp
body: <p>I have a JSP page in which I have two  tags. In first  I am trying get input such as Car Maker name such as Tata, Hyundai, Toyota, Audi etc. When user selects any option in first , it should display car models from that maker such as Innova,Land Cruiser etc. So when user selects any option in first  tag, I am calling a servlet which gets all the models from database in a list and setting the list as attribute of session and forwarding the request back to JSP. But in jsp when I try to fetch the list it is giving NULL POINTER EXCEPTION. How to solve it? 
  The code is as below:</p>
  
  <p>DbReviewCar.java</p>
  
  <pre><code>    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  
      Connection conn= null;
      PreparedStatement pstmt= null;
      ResultSet rs;
      String sql= null;
      String maker= request.getParameter("make");
      List modellist= new ArrayList();
      /*if(maker==null)
      {
          modellist.add("ferrari");
          modellist.add("hummer");
           request.getSession().setAttribute("value", modellist);
           request.getRequestDispatcher("CarReview.jsp").forward(request,response);
  
  
      }
      else
      {*/
  
  
      try {
          Class.forName("com.mysql.jdbc.Driver");
          conn= DriverManager.getConnection("jdbc:mysql://localhost/cardetails", "root", "Welcome123");
          sql= "select model from cars where make=?;";
          pstmt= conn.prepareStatement(sql);
          pstmt.setString(1, maker);
          rs= pstmt.executeQuery();
          while(rs.next())
          {
              String mod= rs.getString(1);
              modellist.add(mod);
              System.out.println(mod+"&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;.");
          }
  
  
      } catch (ClassNotFoundException e) {
  
          e.printStackTrace();
      } catch (SQLException e) {
  
          e.printStackTrace();
      }
  
  
       request.getSession().setAttribute("value", modellist);
       request.getRequestDispatcher("CarReview.jsp").forward(request,response);
      }
  </code></pre>
  
  <p>CarReview.jsp</p>
  
  <p>Here is my JSP file</p>
  
  <pre><code>&lt;form action="DbReviewCar" method="get" name="myform"&gt;
      &lt;table&gt;
          &lt;tr&gt;
              &lt;td&gt;
          &lt;tr&gt;
              &lt;td&gt;Make:&lt;/td&gt;
              &lt;td&gt;&lt;select name="make" onchange="this.form.submit()"&gt;&lt;option&gt;select&lt;/option&gt;
                      &lt;option&gt;Maruti&lt;/option&gt;
                      &lt;option&gt;Ford&lt;/option&gt;
                      &lt;option&gt;Honda&lt;/option&gt;
                      &lt;option&gt;Skoda&lt;/option&gt;
                      &lt;option&gt;Tata&lt;/option&gt;
                      &lt;option&gt;Audi&lt;/option&gt;
                      &lt;option&gt;Toyota&lt;/option&gt;&lt;/select&gt;&lt;br&gt;&lt;/br&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  
          &lt;%
              List list = new ArrayList();
              list.addAll((List) (request.getSession().getAttribute("value")));
          %&gt;
  
  
  
          &lt;tr&gt;
              &lt;td&gt;Model:&lt;/td&gt;
              &lt;td&gt;&lt;select name="model"&gt;
  
  
                      &lt;%
                          for (int i = 0; i &lt; list.size(); i++) {
                      %&gt;
                      &lt;option value=&lt;%=list.get(i)%&gt;&gt;&lt;%=list.get(i)%&gt;&lt;/option&gt;
                      &lt;%
                          }
                      %&gt;
              &lt;/select&gt;&lt;br&gt;&lt;/br&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;Rating For Style:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="style"&gt;&lt;br&gt;&lt;/br&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Rating for comfort:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="comfort"&gt;&lt;br&gt;&lt;/br&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Rating for Performance:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="performance"&gt;&lt;br&gt;&lt;/br&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Rating for FuelEconomy:&lt;/td&gt;
              &lt;td&gt;&lt;input type="text" name="economy"&gt;&lt;br&gt;&lt;/br&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Review:&lt;/td&gt;
              &lt;td&gt;&lt;textarea cols="18" rows="3"&gt;&lt;/textarea&gt;&lt;br&gt;&lt;/br&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
          &lt;tr&gt;
              &lt;td&gt;&lt;Button&gt;Save&lt;/Button&gt;&lt;/td&gt;
              &lt;td&gt;&lt;input type="reset" name="cancel" value="Cancel" /&gt;&lt;/td&gt;
          &lt;/tr&gt;
  
  
  
  
  
  
      &lt;/table&gt;
  
  
  &lt;/form&gt;
  </code></pre>