This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Applet - Servlet Communications

 
Steve Campbell
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic