aspose file tools*
The moose likes Servlets and the fly likes Applet - Servlet Communications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Applet - Servlet Communications" Watch "Applet - Servlet Communications" New topic
Author

Applet - Servlet Communications

Steve Campbell
Ranch Hand

Joined: Dec 18, 2000
Posts: 41
I'm writing an application which will use servlets and applets. I have "Core Servlets and JavaServer Pages" turned to section 17.3 (Reading Serialized Data Stuctures) which outlines servlet to applet communication. I'm using JDK v1.3 and Tomcat 3.2 and Win 2000. I've written a couple of other apps using this same setup, but this is the first time that I'm using an applet.
I put in extensive try/catch blocks everywhere. I'm getting caught on is step 5 of the Core book.
The steps are:
1) Create a URL object
I tried changing the url suffix to a number of different things. My Tomcat application name is "wms", so it's under \webapps\wms. I create a subdirectory under wms of "jsp" (the only other sub is "web-inf".
2) Create a URLConnection - this doesn't get "caught", so I guess it works
3) Disable cache
4) Set any HTTP Headers - at this point I don't set any (should I)?
5) Create an input stream
try {
in = new ObjectInputStream(connection.getInputStream());
} catch(IOException ioe) {
JOptionPane.showMessageDialog
( null, "ListApplet: new OIS - IOException2 = " + ioe,
"ListApplet error",
JOptionPane.INFORMATION_MESSAGE );
} catch(Exception e) {
JOptionPane.showMessageDialog
( null, "ListApplet: new OIS - Exception2 = " + e,
"ListApplet error",
JOptionPane.INFORMATION_MESSAGE );
}
I alway catch the first exception (UIException) with ioe = "java.io.FileNotFoundException: http://localhost:8080/wms/jsp/ListServlet". Since this is derived from step 1 above I changed that to a number of different things, but I can't find the correct answer.
6) Read the data structure with "readObject"
try {
dbResults = (DBResults) in.readObject();
} catch(ClassNotFoundException cnfe) {
JOptionPane.showMessageDialog
( null, "ListApplet: in.readObject - ClassNotFoundException = " + cnfe,
"ListApplet error",
JOptionPane.INFORMATION_MESSAGE );
} catch(OptionalDataException ode) {
JOptionPane.showMessageDialog
( null, "ListApplet: in.readObject - OptionalDataException = " + ode,
"ListApplet error",
JOptionPane.INFORMATION_MESSAGE );
} catch(Exception e) {
JOptionPane.showMessageDialog
( null, "ListApplet: in.readObject - Exception3 = " + e,
"ListApplet error",
JOptionPane.INFORMATION_MESSAGE );
}
I catch on "Exception" with a null pointer error. When I changed this from a data structure to a string array, I was able to read from the servlet in spite of above errors (I think).
Can anyone help me with the Applet - Servlet communications?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Applet - Servlet Communications