This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Applets and the fly likes Applet and Servlet connection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Applet and Servlet connection" Watch "Applet and Servlet connection" New topic
Author

Applet and Servlet connection

bill dimitry
Greenhorn

Joined: May 27, 2008
Posts: 5
Hi guys,
I've done some testing and my basic code is working. By using a test class I am able to connect to a servlet, get records from a database and print them in the test program. Check this post.
By using the same base classes I am trying to get the DB records into an Applet. The previous test is working fine but now when I try to get data into the Applet I get an error message and a blank applet.
I�ve been using NetBeans 6.1 IDE.

I think that my web app structure is the problem.
Please notice that after every compilation I drag and drop mainApplet.class from web/WEB-INF/classess/ folder to the web folder root.
The best option would be to place mainApplet.class in class/all/ subfolder together with all other classes, but I don�t know how to call it from the jsp page (<APPLET CODE=�mainApplet.class�).
I�ve tried CODE=�all.mainApplet.class� but it doesn�t work.

Thanks,
Bill

NETBEANS SOURCE FOLDER STRUCTURE:
Src/config
Src/java/mainApplet.java
Src/java/all/Course.java
/GetCluster.java

NETBEANS WEB FOLDER STRUCTURE:
Index.jsp // JSP wrapper page
mainApplet.class//Applet class
WEB-INF/classess/all/Course.class//Course object class
/all/GetCluster.class//Servlet class

EROR MESSAGE:
bobo: java.lang.ClassNotFoundException: all.Course
java.lang.ClassNotFoundException: all.Course
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at java.io.ObjectInputStream.resolveClass(Unknown Source)
at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readArray(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
at java.io.ObjectInputStream.readSerialData(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at mainApplet.getRecords(mainApplet.java:350)
at mainApplet.createNodes(mainApplet.java:150)
at mainApplet.buildGraph(mainApplet.java:295)
at mainApplet.init(mainApplet.java:115)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

JSP PAGE CODE:


Here is the Applet code causing the error. The same two methods I've used in the testing class without a problem.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41582
    
  54
NETBEANS WEB FOLDER STRUCTURE:
mainApplet.class //Applet class
WEB-INF/classess/all/Course.class //Course object class

All applet classes must be publicly accessible, not just the main applet class.


Ping & DNS - my free Android networking tools app
bill dimitry
Greenhorn

Joined: May 27, 2008
Posts: 5
Thanks Ulf,
I've moved all classes on the root level where jsp page is located and it works now.
On Monday I'll keep working on it.
Have a nice weekend.

Kind Regards,
Bill
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41582
    
  54
By the way what does "I�ve tried CODE=�all.mainApplet.class� but it doesn�t work" mean? You're right that you should put classes in packages, and generally that works fine. You could try "code=all.mainApplet" instead of "code=all.mainApplet.class".
muthu bharathi
Ranch Hand

Joined: Dec 10, 2008
Posts: 97
Hi,
Can you share your code? im also need this code.....

Thanks in advance..



-- cheers
M. Bharathi
 
jQuery in Action, 2nd edition
 
subject: Applet and Servlet connection