Figuring out the correct approach.. :S

D

Dave Brown

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top