• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Tomcat 7 jsp/DAO Problems

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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:

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic