Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSPs and Vectors....  RSS feed

 
Stone Golem
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I use a JSP or Servlet to hit the database for a list, for ex. a customer list, and I want to present it, do I have to present it in the same page/servlet or can I pass the list to another JSP page to present it? How if possible? I was thinking of using a vector, but the texts I refer to don't have much info!
Thanks in advance for your response.
Stone.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to take the Vector and place it on the HttpRequest context using request.setAttribute("some_name", myVector);
You can then forward (using the forward() method of requestDispatcher) to another servlet or JSP. That Servlet or JSP can then pick up your Vector using request.getAttribute("some_name) and display it.
Kyle
P.S. Most good servlet books do cover this in some detail. Look for ones that describe the MVC or "Model 2" architecture.
------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure you can (and probably should) provide presentation in another class.
As a quick intro, you can send your request (initially) to a Servlet, get it to gather the data then DISPATCH the request somewhere else to take care of the presentation...

Now the jsp gets called (from the server side) and is passed the same request and response objects (plus the extra stuff we put on it)

The point is that you have (fairly weakly) separated your presentation logic. The business logic and persistance logic are still in the Servlet together, but if you assume that the "get stuff from db" call in the Servlet accesses something else, then you have separated each of the layers.
(on a side note, usually you use ArrayList instead of Vector, and I always treat them all as a Collection)
Hope this helps
Dave.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Heh, thats what I get for taking so long with my reply. It's all good though!
 
Kavita Ghia
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,
U don't have to worry that u don't get anything for talking so much.I saw ur post and it helped me.There must be many others like me who would have cleared their doubts.Thanks
Kavita
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!