This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Unable to found class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Unable to found class " Watch "Unable to found class " New topic
Author

Unable to found class

Balasubramani Dharmalingam
Ranch Hand

Joined: Dec 06, 2004
Posts: 116
hai friends ,
i am using tomcat 5.0.28 . i have written simple jsp page as follows ,

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

</body>
</head>
</html>

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



org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:332)
org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:412)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:472)



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.


Balasubramani SD,<br />SCJP 1.4,SCWCD 1.4,SCJP 5.0<br /><a href="http://sd.balasubramani.googlepages.com" target="_blank" rel="nofollow">www.sd.balasubramani.googlepages.com</a>
Pranav Shukla
Ranch Hand

Joined: Oct 05, 2005
Posts: 64
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.


Pranav Shukla
SCJP, SCWCD, SCBCD
 
GeeCON Prague 2014
 
subject: Unable to found class