• Post Reply Bookmark Topic Watch Topic
  • New Topic

request dispatch question

 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am sure it is simple, coming back to web programming after a while, but I cann't seem to recollect how a request is forwarded from a servlet to a jsp.

The servlet first interacts with the database, gets the resultset and then where exactly should I add this object so it would be visible to the jsp?


[ August 16, 2007: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I avoid dealing with resultSets in JSP.
Instead, I usually deal with the resultSet in a Java class, move the data to a collection that is not database dependent, clean up all the connection, statment, and resultset stuff, and return the collection to the servlet.
Then, from the servlet, I bind the structure to request scope just before forwarding.
[ August 15, 2007: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65516
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ben's description is indeed the best-practice pattern that you will find most experienced web developers following.

In best case, your DB access code will be completely independent from the UI.
 
subodh gupta
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keeping the patterns issue aside the answer is



Will work for you.
 
Brian Percival
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah Subodh thanks!!

Ben and Bear, thanks too, I am changing my approach. I was trying to ' just get it to work' for now, but better start on the right path even for that.
Thanks for your time...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!