aspose file tools*
The moose likes Beginning Java and the fly likes Questions about Import 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 » Beginning Java
Bookmark "Questions about Import" Watch "Questions about Import" New topic
Author

Questions about Import

Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
Hey There,
I'm trying to use my first ever extended class, but I don't know if I'm importing it correctly. The error I'm getting is "Unable to compile class for JSP". I'm quite the noob, hence my posting in this forum. Thanks a lot!

Cheers, Mike

My class "newPolygon" is as follows:


And my jsp is:


and my class is located at examples\WEB-INF\classes\GoogleDir\newPolygon.class
and my jsp lives at
examples\
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

You cannot use AWT in JSPs. You should use Applets if at all you want to use Java for drawing the front-end.
Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
Hey Abhinav,

Thanks for the note - and I'm hardly the expert, but I don't think you're totally correct. I have sucessfully imported and called methods from the Polygon class from a JSP - so I'm sure that the AWT package can be used.

I think the problem is that I'm now extending that polygon class.

Cheers,
Mike
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14270
    
  21

The problem is in this line in your JSP:

<%@ page import="classes.GoogleDir.*"%>

What you write after "import" is not the name of a directory, but of a Java package under WEB-INF/classes. To make this work, you should change this to:

<%@ page import="GoogleDir.*"%>

And you should put your newPolygon class in a package named GoogleDir by adding the following line at the top of the Java source file:

package GoogleDir;

(Note that "GoogleDir" is a strange name for a package; normally you would use a "reversed URL" form with lower-case letters, for example "com.mycompany.mypackage").

See: The Java Tutorial - Creating and Using Packages


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Abhinav Srivastava
Ranch Hand

Joined: Nov 19, 2002
Posts: 349

your are right, awt can be used in servlets/jsps.

any calls to the AWT toolkit in versions of Java 2 SDK before 1.4 require that the machine running the code have a valid display context, namely X Windows. In the Java 1.4 Platform, Sun made our lives much easier and addressed the lack of headless AWT support. Instead of setting up a dummy X server like Xvfb, just put the parameter "-Djava.awt.headless=true"
Mike McMahon
Ranch Hand

Joined: May 07, 2005
Posts: 30
Thanks guys,
I got it working.
The polygon class is very close to what I need, but the addPoint(int x, int y) method needs to accept doubles. I tried to address this by overriding the method "public void addPoint(Double x, Double y){}".

The class compiles just fine and I can access it's methods. As you can see in the jsp, I can use addPoints with doubles just fine, and polys are created. However, when I try to test the contains(method), it only seems to work when addPoints is loaded with integers - if the polygon uses doubles, contains() always returns false.

Any thoughts why?

Thanks guys,
Mike

Java class

jsp code:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Questions about Import