title: Send array of objects from servlet to JSP
body: <p>I want to send array of my own objects to JSP page by request.</p>
  
  <p>At this part of code in servlet I'll get my data, put it on array of objects, and set them to request.</p>
  
  <pre><code>     if (request.getParameter("todo").equals("show_article_list")) {
           try {
               Article[] articles = this.getArticleList();
  
               request.setAttribute("articles", articles);
              RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("article/article_list.jsp");
              dispatcher.forward(request, response);
           } catch (Exception e) {
           }
       }
  
      public Article[] getArticleList() throws Exception {
      db data = new db();
      Connection con = data.OpenConnection();
  
      PreparedStatement statement = con.prepareStatement("SELECT * FROM `article`");
      ResultSet result = statement.executeQuery();
  
  
      int size = 0;  
      if (result != null)   
      {  
          if (result.last()) {
              size = result.getRow();
              result.beforeFirst();
          }
      }  
  
      Article[] articles = new Article[size];
      int i = 0;
      while(result.next()){
          articles[i] = new Article (
                  result.getInt(1),
                  result.getString(2),
                  result.getString(3),
                  result.getString(4));
          i++;        
      }
  
      return articles;
    }
  </code></pre>
  
  <p>This is my class:</p>
  
  <pre><code>public class Article {
  public Integer getId(){return id;}
  
  public String getTitle(){return title;}
  public void setTitle(String title){this.title = title;}
  
  public String getText(){return text;}
  public void set(String text){this.text = text;}
  
  public String getDescription(){return description;}
  public void setDescription(String description){this.description= description;}
  
  private Integer id;
  private String title;
  private String text;
  private String description;
  
  public Article(Integer Id, String Title, String Text, String Description)
  {
      id = Id;
      title = Title;
      text = Text;
      description = Description;
  }
  }
  </code></pre>
  
  <p>On my JSP page, I want to loop such array of objects using <code>request.getAttribute("articles");</code> How I can do it? </p>
  
  <p>I must use <code>&lt;jsp:useBean/&gt;</code> or something else? I tried to do this way: </p>
  
  <p><code>Article[] articles = request.getAttribute("articles");</code> </p>
  
  <p>But I have an error: <code>Article cannot be resolved to a type</code> </p>
  
  <p>What I did wrong?</p>