I have links in my Tomcat container that if someone clicks on a specific link it should go to a Record page (Show.jsp) with all the values associated with a record from a database. For example if someone clicks on a specific link like this: <a href="Show.jsp?lastname='Jones'">LinkExample</a> it would take you to a jsp with database info for someone named Jones and show you his info: Lastname = Jones Firstname = Mike City = San Diego
I would like to do this using a Java helper class and bean so I dont have any database connection or Java code in my JSP.
I created Java class file that has Database connection that works with a Java bean. I just dont know how to get the Show.jsp to work with the Java Bean and Java helper class file.
Here is what I have for Show.jsp and this is the part I have been working on the longest but cant get it to work because it doesnt seem to work with the database:
My Java Helper class that compiles and connects to database:
My Java Bean that compiles here:
[ April 22, 2007: Message edited by: Mike Jenkins ]
Originally posted by Bear Bibeault: Before doing anything else, please let us know what container and version of JSP that you are using. The code you posted is doing things using old-fashioned mechanisms and patterns.
I am using Tomcat 4.1.27 with JDK 1.4 and I dont have JSTL due to restrictions in my environment for downloading software.
What i'd do is to have the original link invoke a servlet. The servlet would delegate the fetching of the user data to a UI-agnostic class in the model (what I think you termed the helper class). The model would return the user information, in the form of a bean-formatted Data Transfer Object (what you are thinking of as the bean) to the servlet. The servlet would tack the bean as a scoped variable onto the request and forward to the JSP.
All of the above is as appropriate for the JSP 1.2 environment as for a more modern setup.
On the JSP is where the main difference lies. In a JSP 2.0 setup, you'd use JSTL and EL. Under JSP 1.2 without JSTL, you'll need to use scriplets and sciptlet expressions.
The <jsp:useBean> action would be used to "hook up" the JSP to the bean that the servlet placed in request scope. The setProperty action you have on your original page is wrong -- it's used to populate a bean from request parameters. Remove it.
You could use the getProperty actions to access the bean, but you could also just use scriptlet expressions.
Joined: Jul 23, 2006
Thanks for your help especially on a Sunday night!
I will now take your guidance and apply it and if any problems I hope I can ask for assistance on here again.