Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

where to put the object passed betweeb servlet and applet

 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have Redhat 9:

Tomcat is able to run at: http://local/exapples, no need http://localhost:8080/examples

Apache web server is running, the home folder is /usr/www/html/

I want to pass a object(my own class) between applet and a servlet. First the Applet passes the opject to Servlet with some parameters, then servlet receives this object and change some data inside the object and pass it back to applet.

My applet is under Apache web server home folder.
My servlet is under $CATALINA_HOME/webapps/examples/ (I am using webapp to connect Applet and servlet)
Now, where shall I put my class, the object passed between applet and servlet? It should be a class like the normal Java public class. I have serialized this object. like the followings:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

class dataStructure implements java.io.Serializable{
int dy,dm;

dataStructure(int arg1){
dy=arg1;
dm=0;
}

}

Please any advise!
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the servlet is to deserialize the object, it must be able to locate the class file. If the servlet lives in /examples, one place you could put the class file is /examples/WEB-INF/classes/yourpackage/dataStructure.class
(your class MUST be in a package)
Naturally the applet must also be able to load the class, but this can't be done from the WEB-INF hierarchy so the class file must also appear where the browser can get it.
See the Tomcat documentation for where to locate classes that need to be visible from more than just one web application.
Bill
 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I put my package in the public Java home, then import my class both in Servlet and Applet, it sould work even my applet and servlet are in other two different folder?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic