• 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

Error : class not found while running jsp

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

Eventhough it looks like a small problem I am unable to solve this,please look to this issue.

My Jsp code :Hello.jsp

<% Employee e = new Employee();
%>

Where Employee is a JavaBean.Is compiled properly.

While running this jsp from Tomcat I am getting the following
ERROR: Employee classnot found.

My Directory structure is as follows:

Tomcat 4.1\webapps\MyApps -- Contains Hello.jsp
Tomcat 4.1\webapps\MyApps\WEB_INF\classes-- Contains Employee.class (Java Bean)

Also I have included the Tomcat 4.1\webapps\MyApps\WEB_INF\classes in the classpath.

I really dont know where the problem is.I would appreciate if someone provides me a correct detail solution.

Thanks,
Sridhar.
 
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
Have you imported the class?
 
sridhar yenamandra
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do i need to import some class if its already present in my classpath?
Anyway tried that way also but still facing the same issue

Regards,
Sridhar.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sridhar yenamandra:
Why do i need to import some class if its already present in my classpath?
Anyway tried that way also but still facing the same issue

Regards,
Sridhar.



If your class is not in the same package as your JSP (which is unlikely) you'll need to import it before you can use it. This is the same as with any Java program.

We get this question a lot and have compiled some of the most common causes in the JSP FAQ:
http://faq.javaranch.com/view?BeansNotFound
 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Package your classes and place them in the proper directory structure in WEB-INF/classes.

ram.
 
sridhar yenamandra
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys! The problem got solved after I placed my bean class in a package inside WEB-INF/classes ,but I still have a doubt.

When I am accessing the Employee class(bean class inside WEB-INF/classes) from a java class in some other package,its not throwing any error and its able to find the Employee class as its set in the classpath.

But error is coming only in case of jsp. why?

Regards,
Sridhar.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Starting with JDK 1.4.xx, classes in the default package (no package declaration) can not be accessed from packages classes. This has always been the rule but previous versions of the JRE let it slip.

Since your JSPs all live a package (org.apache.jsp for Tomcat), they won't be able to access beans living in the default package.

I'm guessing that your command line app was also in the default package and was, thus, able to access the Employee class.
 
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic