• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Calling ArrayList from class

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm new to Java programming. I am currently trying to pass my Arraylist form the class i used in the project. Below is my arraylist from class:

Usertable.java



My jsp form for the options:


What kind of statement should i add on the jsp in order to retrieve the ArrayList from Usertable class? thank you.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Presumably there is an instance of Usertable added into your request object by your servlet.
The JSP page should then be able to use a suitable JSTL tag to iterate over the list (c:forEach in this case).


(That's not copy/paste code)

Where "items" is the entry in your request that your servlet added.
 
Emir Rayhan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i'm sorry but i don't understand fully. Your solution is getting me there but i don't have an idea to iterate. Maybe i can show you more source code.

Usertable.java



studentServlet.java



Jsp page



and I also planning to use radio as the input type.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your model seems a bit confused.

You clearly have a database backing this, with that UserDao.
So I'm not sure why the User class (why call it Usertable?) has a list of courses.
I would expect that to be pulled from the database, or if need be just a static, immutable, List somewhere.

In any case, the only thing you are currently adding to your request is the course chosen.
You need to add the list of courses, so then you can use the forEach tag to iterate over them.
 
Emir Rayhan
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:So I'm not sure why the User class (why call it Usertable?) has a list of courses.
I would expect that to be pulled from the database, or if need be just a static, immutable, List somewhere.



Actually, Usertable is made to avoid naming sensitivity in MySql and the courseOption arraylist does not belong to the database, it is basically an addition list of course object to provide data in the JSP interface.



 
Dave Tolls
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, but it's not related to the User.
The User has a course, but it doesn't have a list of all the courses.

Either way, that list needs to be sent to the JSP i the same way you are sending the course.

And the naming, you can tell whatever persistence framework you are using to use a different name for the table than the class name.
That saves you running into these sorts of issues.

 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic