• Post Reply Bookmark Topic Watch Topic
  • New Topic

what is the best practice?  RSS feed

 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an online book store I'm making using the MVC pattern. I've created links to each book category which I want to display all the books within the corresponding category when they are selected. So basically, a user will click on a link which has the category id embedded in the url. The servlet will pick up that request and send the id over to my model which will query the database for the books.
My question is, how should this information be returned back to my servlet, and eventually retrived by my jsp page which will display the result?? In an ArrayList?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36446
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jason,
Yes, an ArrayList is a good data structure to use. It would contain value objects with the relevant fields. For example, you could create an object with book id, name and price.

Then you place the List into the request (in the servlet) so the JSP can retrieve it as an attribute.
 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's perfect, I was unsure as to what would be the best way to go about it. I didn't want to start working on this section of my webapp and find out that there are more efficient ways to do so!!

Thank you so much!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!