• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions about Import

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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\
 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Abhinav Srivastava
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic