File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Unable to find class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to find class" Watch "Unable to find class" New topic
Author

Unable to find class

Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
Can you tell me what is wrong in the following 2 lines of code?
This is in a JSP.
<%
A obj = new A();
obj.greeting();
%>

I have a class A which has been stored under the classes subdirectory in Tomcat.
Getting an exception - Unable to find class A.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61202
    
  66

Did you import the class?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
Yes, I did.
In the line on top:
import="java.util.*, A.java"
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
You don't specify the "java" portion when you import. Simply importing "A" will suffice. In addition, the JSP container might not be able to compile the JSP document when you try and import classes that are part of the default package.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
<%@ page contentType="text/html; charset=iso-8859-1" language="java" import= "A" errorPage="" %>
Still getting 3 errors-
C:\Tomcat\work\Standalone\localhost\app\mypage_jsp.java:8: '.' expected
import A;
^
C:\Tomcat\work\Standalone\localhost\app\mypage_jsp.java:116: cannot resolve symbol
symbol : class A
location: class org.apache.jsp.mypage_jsp
A obj = new A();
^
An error occurred at line: 57 in the jsp file: /mypage.jsp
Generated servlet error:
C:\Tomcat\work\Standalone\localhost\app\mypage_jsp.java:116: cannot resolve symbol
symbol : class A
location: class org.apache.jsp.mypage_jsp
A obj = new A();
Can you please help me?
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
Lucky,
As I said, Tomcat can't compile a JSP document that tries to import classes that are defined in the default package. (Like your "A" class!) You need to put "A" in an actual package (e.g. com.yourdomain.A). Then it will work.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to find class