• Post Reply Bookmark Topic Watch Topic
  • New Topic

Printing ArrayList of Objects in JSP

 
Jeremy McNally
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would you display an ArrayList of Objects in a JSP page from a Servlet. Any general example would be fine as long as the example is thorough.

Each created object has more than maybe 6 or 7 properties that all need to print to the JSP.

Would you also include ways of printing it like should it be printed by using a table structure in the JSP and if so how? Things of that nature so that way it is each object has its own line and looks good. I can format it myself, I just need to know how to get it in a table for each object to print on its own row and so on...
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeremy McNally wrote:How would you display an ArrayList of Objects in a JSP page from a Servlet. Any general example would be fine as long as the example is thorough.

  • Set the List (the fact that it is an ArrayList is irrelevant) as a scoped variable in request scope using setAttribute(). Choose a good name for the variable that follows identifier conventions.
  • Forward to the JSP.
  • Use <c:forEach> to iterate through the list.
  • Profit!


  • Each created object has more than maybe 6 or 7 properties that all need to print to the JSP.

    You know how to use the EL and <c:out>, right?

    Would you also include ways of printing it like should it be printed by using a table structure in the JSP and if so how?

    HTML, baby! One thing that the experienced members here will always suggest is to design your HTML first. Then, when your HTML and CSS are correct, and only then, write the JSP to generate that HTML.

    I can format it myself, I just need to know how to get it in a table for each object to print on its own row and so on...

    You know HTML table syntax, right?

    Remember, a JSP is just a template for HTML.
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Posts: 65522
    105
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    If you have not done so, I highly suggest reading these articles:
  • The Secret Life of JSPs
  • The Front Man

  •  
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!