File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes jsp and java beans question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "jsp and java beans question" Watch "jsp and java beans question" New topic
Author

jsp and java beans question

preeti dengri
Ranch Hand

Joined: Nov 30, 2000
Posts: 111
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.
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
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.
Ganesh Anekar
Ranch Hand

Joined: May 13, 2001
Posts: 36
Hello,
For this u can use Connection Pooling...
For entire code pls refer...Sam's Publication ..Developing Java servlets book...
Ganesh
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: jsp and java beans question
 
Similar Threads
which method is better..
a jsp design question...
Javabeans and socket error?
What is best way to display a results set from a database?
User Login Page