• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jsp and java beans question

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am having a basic query regarding jsp and beans.when a request is made to a servlet from a jsp page and the sevlet calls respective jsp pages as responses.the individual jsp pages inturn ask a bean to open a database connection ,what is generally supposed to be a good design-- sending results from the bean directly as html(like as a table tag) or as a jsp page.
one more thing ,If several database queries are to be made is there any need to close the connection to that database??Can we use connection pooling inside beans??
please help with a sample code.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
then the database access bean must be of application scope right.
We follow a servlet-centric design approach @ our place.
So there's no database specific code in the jsp. It is used only for presentation.
There can be a "view" object which contains the data to be displayed..ie the display s'd be already filled in.
The jsp can fetch it from the request.
identify the business objects specific to your application.
Once you have done that define method for that .
Eg : Reservation
so possible methods/operations can be save, update , delete..so on.
Associate a command with the JSPs ( have ids for save/update/delete) pass that id from the jsp to the servlet while submitting.
The servlet can do a look up and find out the Business object responsible for that operation.
Let all Business objects implement a interface which say has a signature like this.
void handleRequest(request,response) throws RequestHandleException{
//get the id passed from the request.
switch(id){
if (save)
call BusinessLogic.save()
if (update)
call BusinessLogic.save()
....
}
}
In business logic do database specific stuff and populate the View Object with the data.
put this view object into the request(HttpRequest).
Eg:
class ViewReservationObject{
getters
setters
}
So when the business method exits, the control is back to servlet, it s'd know the next jsp to be displayed(targer jsp)
so the servlet can use the request dispatcher to forward the request to that jsp. So now the view object is available with the request.
If i'm not clear here, buy
Web development with Java server pages..Duane K fields et all.
It's probably the best jsp book out in the market.
rgds
karthik.
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
For this u can use Connection Pooling...
For entire code pls refer...Sam's Publication ..Developing Java servlets book...
Ganesh
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

there are several "free" implementations of connection pooling. one of them is http://javaexchange.com/ which is published under the GnuGeneralPublicLicense. i did not test this one.

pascal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic