Helma logo
helma.org » Home > faq > How can I set a global variable?

How can I set a global variable?

Because Helma processes requests in threads with possibly multiple JavaScript interpreters, you never should set a global variable simply by stating e.g. "pi = 3.141", because it would be only by chance that Helma returns the correct value for the variable pi in a later request.

If you need a global variable across several requests, you should either add an appropriate property to the application object or to the user's session data cache:

app.data.pi = 3.141;
session.data.myGlobalVar = "Hello, World!";


Anyway, if you need the variable even after Helma was restarted, there is no way around storing it persistently in the database or eventually putting it into the app.properties file.


Up: Frequently Asked Questions (FAQ)
Previous: Can I create a Hop action with a function declaration? Next: How can I display log messages in the console window?


Page last modified on 2003-05-13 14:31 by hns