• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to found class  RSS feed

Ranch Hand
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai friends ,
i am using tomcat 5.0.28 . i have written simple jsp page as follows ,

<title> :: Sample page </title>
<%= Sample.getData() %>


here Sample is the class without any package structure as follows ,
public class Sample {
public static String getData() {
return "From Sampl.class" ;

i have put this class file immediately under the classes directory of WEB-INF .
When try to access sample.jsp the following error is occur...
org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 1 in the jsp file: /sample.jsp
Generated servlet error:
/home/bala/jakarta-tomcat-5.0.28/work/Catalina/localhost/IMS/org/apache/jsp/sample_jsp.java:42: cannot resolve symbol
symbol : variable Sample
location: class org.apache.jsp.sample_jsp
out.print( Sample.getData() );
1 error


But if i create this Sample class under some package structure
(ie., like pack.Sample ) it is working fine ..

wht is the wrong in this ...?

thanks in advance.
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot access a class in an unnamed (default) package as per JSP 2.0 Specification]. See the following excerpt from JSP Specification Section JSP.11.2 (Page #255 of the pdf).

As of JSP 2.0, it is illegal to refer to any classes from the unnamed (a.k.a.
default) package. This may result in a translation error on some containers,
specifically those that run in a JDK 1.4 or greater environment. It is unfortunate,
but unavoidable, that this will break compatibility with some older JSP
applications. However, as of JDK 1.4, importing classes from the unnamed
package is not valid (see http://java.sun.com/j2se/1.4/compatibility.html#source
for details). Therefore, for forwards compatibility, applications must not rely on
the unnamed package. This restriction also applies for all other cases where
classes are referenced, such as when specifying the class name for a tag in a TLD.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!