Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / JavaBeans / March 2005

Tip: Looking for answers? Try searching our database.

Figuring out the Correct Approach <scratch head>

Thread view: 
Dave Brown - 08 Mar 2005 17:44 GMT
Hi All,

I'm new to Java, been at it for 3 days now and come up against something
 that google hasnt been able to help with.

I'm trying to determine that correcet approach to something, let me
outline my application. ( JSP App, written in netbeans )

My Application has a Listener which when first started will connect to a
database and place a (Connection) object in the servletcontext
attributes for access through my other jsp's and servlets..

I have a simple login page which is a jsp, takes a name and password
which posts to a login servlet. Which in turn validates the credentials
in the database and if Ok creates an instance of a 'SiteUser' Bean and
attaches that to the Session context(again using setAttribute).
A requestDispatcher then forwards the user to a "UserProfile" JSP
showing the users associated data.  I display this in the jsp with a
<usebean> call at the top and lots of EL syntax tags "${}" to display
the data on the page.

My problem i've hit is I have not yet learnt the JSTL stuff , (that
comes later in my book ;) )   But I want to see if I can solve this
problem without using JSTL.  Anyway I have to output a whole set of data
 from the database onto the page. I 'DO NOT' want to put scripting in
the page, Desperately trying to stay away from that, So I thought what I
could do is use a 'get' function in the "userbean" to connect to the
database.  that way I can use a simple EL ${} tag in the jsp.  BUT
here's where i'm stuck..  The bean does not have a servletContext so it
cannot access the database connection.  I have a Library class which i
use to hold some other database access logic, it would make sense to
include my routine in there also. But when i tried that i was getting
Symbol not found error with "Library" and besides also it meant using
scripting anyway in the jsp with a long tag such as...

out.println(Library.myFunction((Connection)
application.getAttribute("DBConnection"),UserBean.getMyData()));

I have that feeling, I've ended up going down the path trying to find a
much more complicated solution than is necessary and missed something
fundamental to the approach i'm using rather than the logic itself.

After trying to find some answeres on google, it seemed quite common
that people setup a Bean to hold the database connection at the
application level as opposed to holding it in an attribute like i have,
but even so how would my userprofile bean access the dataconnection bean
if I set one up.

Ah well, any thoughts and advice greatly appreciated.

Regards,

Dave.
Oscar kind - 08 Mar 2005 18:23 GMT
> My Application has a Listener which when first started will connect to a
> database and place a (Connection) object in the servletcontext
> attributes for access through my other jsp's and servlets..

Ouch! This will cause a connection timeout when a user opens the
application and takes a cup of coffee...

The correct approach is to open the connection for each page access, and
close it before you return to the browser. An improvement in your design
would be to put a connection pool of connection factory in the servlet
context.

Signature

Oscar Kind                                    http://home.hccnet.nl/okind/
Software Developer                    for contact information, see website

PGP Key fingerprint:    91F3 6C72 F465 5E98 C246  61D9 2C32 8E24 097B B4E2



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.