aspose file tools*
The moose likes JSP and the fly likes Error : class not found while running jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Error : class not found while running jsp" Watch "Error : class not found while running jsp" New topic
Author

Error : class not found while running jsp

sridhar yenamandra
Greenhorn

Joined: Jul 27, 2004
Posts: 19
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

Joined: Jan 10, 2002
Posts: 61433
    
  67

Have you imported the class?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
sridhar yenamandra
Greenhorn

Joined: Jul 27, 2004
Posts: 19
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

Joined: Dec 11, 2004
Posts: 13410

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


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Package your classes and place them in the proper directory structure in WEB-INF/classes.

ram.
sridhar yenamandra
Greenhorn

Joined: Jul 27, 2004
Posts: 19
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

Joined: Dec 11, 2004
Posts: 13410

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
 
subject: Error : class not found while running jsp