I'm not quite sure what you are asking here, but I don't see anything bad, including <script> tags in the JSP to generate JavaScript code. I often follow this model by writing library code to external javascript files, and then calling the constructors for my objects from the <script> tags.
This makes debugging easier, as the logic is in external files (and firebug seems to have problems debugging the javascript inline code). Libraries receive caching, but the data that creates them is not (which is the desired behavior).
An alternative is to create dynamic instantiation code in an external javascript file or AJAX call. I also did this with positive results.
I think the deciding factor is how much dynamic data you have. If you need to represent large data structures, I would serve them through an AJAX call that returns JSON. If this is a simple call to the constructor, put it in the JSP.
As for the global variable, I will often have a global object for the top level that repels everything. Inside this, all other references to auxiliary objects.
pkaeding
source share