File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error : class not found while running jsp

 
sridhar yenamandra
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64205
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you imported the class?
 
sridhar yenamandra
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic