Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Tomcat 7 jsp/DAO Problems

 
john gere
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using tomat 7.0.8. I am trying to access basic information in a database using the DAO (direct access object) design pattern. The problem I am having is that the data shows fine when I use a servlet. However, when trying to use a jsp file (which is preferred) I get an error that says the DAO object is not a recognized type. Here are the details:
Working Servlet:

Jsp That does not work

Up to this point I have not been using Ant or any kind of deployment software. I manually created my root folder brain(C:\Tomcat7.0\webapps\brain) and in it are my jsp files. The WEB-INF folder that has the classes folder, in which are all the classes, is also in brain.(C:\Tomcat7.0\webapps\brain\WEB-INF\classes). To ensure clarity here is the main part of the error message that Tomcat spits out:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The time to be putting Java code in a JSP is long long past. Doing so is not preferred, in fact, at this stage it's irresponsible.

Keep the Java code in a Servlet, and use JSP only to generate the HTML views using JSTL and EL.
 
john gere
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. But as you see I will need to pass an Array List from a servlet to a jsp. How do I do that? I know how to pass data from a servlet to a jsp using a session.



I assume this is not the preferred method. Setting a session to pass object data does not seem efficient?
 
john gere
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition, the code submitted is for coursework. Its just to get an understanding of the process. Having said that, why don't the jsp recognize my dao object?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you need to use the session? Attach the scoped variable to the request.
 
john gere
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the help. I have resolved the issue by using a servlet and then passing the data to the jsp.
Servlet Code:

Jsp code:

Once again thanks!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64973
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A good step in the right direction!

The next step to take is to learn the JSTL and EL and replace all Java code on the JSP!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic