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 Trying to figure out the correct approach... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Trying to figure out the correct approach..." Watch "Trying to figure out the correct approach..." New topic
Author

Trying to figure out the correct approach...

Dave Brown
Ranch Hand

Joined: Mar 08, 2005
Posts: 301
Hi All,

I'm new to Java and to these forums, I got the Head First servlets book and have been at it for 3 days now and have been attempting to convert some of my older non java projects and have come up against something that google hasnt been able to help with.

I'm trying to determine that correct solution 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, that I may be straying from the path so i'm looking to closely at the wrong things to fix something that i shouldnt be trying to fix if only i'd have gone down the right path at the start anyway.... or something like ;-)

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 if I go down hat route, how would my userprofile bean access the dataconnection bean if I set one up. Can beans speak to other beans ? ( one of those questions I like to try to explain to people who have never heard any java terminology ! )

Ah well, any thoughts and advice greatly appreciated.

Regards,

Dave.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

"Unique Dave"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Trying to figure out the correct approach...
 
Similar Threads
JSP 2.0 JSTL
SocketPermissions on http
EJB, JSPs and JDBCs
sample jsp page calling database access bean
Variable defined in one JSP scriptlet not visible in another