Pergunta

my problem is store some user inputs in applet to reduce user operations. I use static fields for that. But I noticed, that if user goes to several tabs in browser - thr new "thread" (or something like this) started, and my static class in this new thread is empty. Maybe there is another solution to save some data in applet?

Edit

Ok. More details. I have an applet for digital signature. User once select certificate (X509Certificate) and use it for sign all documents. I have a class like this:

   public class CertificateContainer
    {
        private static X509Certificate certificate;
        ...
Foi útil?

Solução

Applets in different browser tabs are independent programs. Depending on the browser and Java-Plugin they may even run in a different VM, but even if in the same VM, they most probably have independent class loaders and will not be able to communicate by static variables.

If you need to store user data, you could use the JNLP API, for example the PersistenceService.

With the 1.6 Sun Plugin, this will only be available if your applet was loaded by JNLP, in the IcedTea Plugin (distributed with some versions of OpenJDK) it is also available for applets loaded by the usual applet tag (without JNLP).

(I have no idea how a CookieHandler would be used by Applets.)

Outras dicas

Using static fields to pass user input between parts of an application is a very bad practice. The data should be stored in objects that are passed around as necessary.

But in your case, for sharing data between multiple applets, the best solution would be to store it in Browser cookies using java.net.CookieHandler

It sounds like you shouldn't be using static fields for storing user data. Also, I don't think a new browser tab would create a new thread because it should be a completely separate instance of your applet.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top