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 In JSP, How to import a java class that exists in default package? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "In JSP, How to import a java class that exists in default package?" Watch "In JSP, How to import a java class that exists in default package?" New topic
Author

In JSP, How to import a java class that exists in default package?

Lakshman Kumar
Greenhorn

Joined: Jan 05, 2007
Posts: 8
I have questions about import java class in JSP,like the following structure

test
|
|__WEB-INF-->classes-->Dog.class
|
|__index.jsp

In classes directory,I put a java class named Dog.class,and I put a JSP file
in test directory,named index.jsp ,and In index.jsp called Dog class,but I
don't use "import",I think JSP can find it.

/*Dog.java*/
public class Dog{
String name;
public Dog(String a){
this.name=name;
}
public String getName(
return name;
}
}

But when I run index.jsp,it raised error:
cannot resolve symbol : class Dog
Then I copy Dog class into test directory,it still raise above errors.

My questions are:
1.I want to know what default path which JSP use class
2.I don't want to use "package" in Dog.java, If I use import in JSP,how to
write this import statement?

Thanks in Advance.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39549
    
  27
You have to put that class into a package. With earlier JVMs you could use classes in the default package, but not any more (I think since Java 5).


Ping & DNS - updated with new look and Ping home screen widget
Lakshman Kumar
Greenhorn

Joined: Jan 05, 2007
Posts: 8
Ya, i even created a folder (foo) under classes directory and placed the Dog.class file and tried it out...but the result is same as earlier (an error).

test-->web-inf-->classes-->foo-->Dog.class

In jsp, i placed <%@ page import="foo.*" %>.
In Dog.java, i placed package foo; as the first line and compiled successfully.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: In JSP, How to import a java class that exists in default package?
 
Similar Threads
Classpaths with packages
In JSP, how to import a java class-in-default_package ?
Head First Servlets and JSp problem
Error LlistenerStart
Symbol not found