Applet - Servlet Communication

Please help. Have been searching the net for months but no avail. I am a novice in Java.

I have an application running on applets. Upon login through my main applet, it will initialises and assign values to all the variables, including all static variables. These variables are not only string variables. My issue is upon successful login, I want to move to my servlet, which I used showDocument(url_of_my_servlet, frame). However in my servlet, all the values in the variables, including static variables are lost. How can I, from my servlet access all the variables and methods set in the applet? By the way, I did not destroy my applet.

i have looked through. However it is just that my situation is different from others as they can pass those parameters through HttpURLConnection. I cant as my parameters cannot be serialised. Many static java objects are created at the applet side, including the connection pool from database.

If the objects are not serializable, then they can't be transferred to the servlet. Things like network connections in particular (which is what a connection pool is), are specific to the machine where they are created.

Ken Flor

Ranch Hand

Posts: 34

posted 11 years ago

Hi,

which means they cannot be transferred to the Servlet?

Is there anyway, besides transferring, in which the variables in Applet can be accessible to the Servlet? Which is to say, can put both Applet and Servlet in the same context, or package, so that all of them are public to each other?

Ulf Dittmer

Rancher

Posts: 42975

76

posted 11 years ago

Applets run on the client, while servlets run on the server, so they're in different JVM instances. There is no way one can access the other w/o some kind of serialization.

actually my application is all solely on Applet. However the login page (build from applet) and all the security and common classes are in terms of applet and many applications are using these classes. My boss wished to change just ONE application to servlet and the rest remains as applet application. I cannot change the Login/Common/Security classes as the rest of the applications are still using these classes. Which is why I need to develop some design that can fit to both applet and servlet.

The login page (applet) will initialises all the variables (just like the existing system). After which my servlet will be loaded based on showDocument(). The servlet should be able to access all these static variables.

Any ideas?

Thanks.

Ulf Dittmer

Rancher

Posts: 42975

76

posted 11 years ago

It sounds like there are dependencies between the security/login classes and tha fact that they are running in an applet. Try to redesign the classes so that those clases don't depend on their environment (i.e., whether it's an applet or a servlet), so that they can be used in both.

Ken Flor

Ranch Hand

Posts: 34

posted 11 years ago

thanks for the reply.

you are right, there are dependencies. I am trying to change the common classes so that it works for both applet and servlets.

However kindly provide ideas if there are.

Thanks so much

William Brogden

Author and all-around good cowpoke
Rancher

Posts: 13078

6

posted 11 years ago

Is there anything in these security/login classes that is inherently impossible to serialize? Bill