Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How to create dynamic rows in jsp according to the number of data read from servlet?

  1. #1
    Junior Member
    Join Date
    Apr 2009
    Thanked 0 Times in 0 Posts

    Default How to create dynamic rows in jsp according to the number of data read from servlet?

    Hi all experts...!!
    I have devoloped a servlet which reads data from DB & the resuslt is set to a session & send it to the jsp. In jsp the result is put to a table(data grid).

    <td width="100" ><%= (ArrayList)session.getAttribute("name") %> </td>
    <td width="100" cellpadding="2" cellspacing="5" border="2"><%= (ArrayList)session.getAttribute("age") %></td>

    My problem is all the data is included in to one row. I need to get all the data row by row. (if 5 names are in the DB , 05 rows should be created.)

    Tell me where I have done the mistake...

    plz help me on this.....

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 294 Times in 227 Posts
    Blog Entries

    Default Re: dynamic table creation

    Hello jam123 and welcome to the Java Programming Forums.

    I am unfamiliar with JSP but would it be possible to put this code in some kind of 'for' loop?

    If you make it loop as many times as there are entries then this would solve your problem.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Warrington, United Kingdom
    My Mood
    Thanked 156 Times in 152 Posts

    Default Re: dynamic table creation

    Yes just like JavaPF says you should loop through the information in your arraylist and print it line by line.

        final List<String> names = (ArrayList<String>) session.getAttribute("names");
        for(final String name : names)
            <td><%=name %></td>

    Something like that or you can use JSTL to do this with tags which might be preferable. I only print out a list of strings in that example but you get the point, you could have a list of objects and print out the selected data from the object using that loop.

    // Json

  4. The Following User Says Thank You to Json For This Useful Post:

    JavaPF (July 8th, 2009)

Similar Threads

  1. Adding Marathi words to MySQL table
    By vaishali in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: July 8th, 2009, 06:43 AM
  2. WAR file creation in Eclipse JEE
    By katty in forum Java IDEs
    Replies: 5
    Last Post: May 21st, 2009, 09:45 AM
  3. Getting table height using JSTL
    By jsnx7 in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: March 19th, 2009, 12:03 PM