Monitor Swing events in JSP
How can I monitor a Swing object's events in a jsp page. Namely, my jsp has an <object> tag which defines a cache_archive param for a jar file. This jar file has a class that creates Swing jbuttons, jpanel and jprogressbar. How can my jsp keep track of these jbuttons and their events?
Thank you,
Igor
Message was edited by:
eazyigz
[371 byte] By [
eazyigza] at [2007-11-27 6:11:18]

You mean an applet? You can't. Once the web page and applet are showing, your JSP page is no longer "running". JSP only generates the HTML, it doesn't keep running while the user looks at the page. It doesn't change how browsers, HTTP and HTML work.
Presuming it's your applet code, you can make it pass info back to the server via URLConnection or AppletContext.showDocument(). But you probably don't want a ton of "events" being passed back. It would defeat the point of having the applet in the page to pass every little thing back. The applet would be there to do all the core stuff and send some results back.
Thanks for your input. So the only way to interact with the Applet's events from the JSP is to modify Applet's code?
There are ways for Java to interact with ECMAScript, but what are you trying to do? What is your goal?
> Thanks for your input. So the only way to interact
> with the Applet's events from the JSP is to modify
> Applet's code?
Like said, what are you actually trying to do?
Cuz my answer to this last question, as written, is no, because as I said, once the applet is running and generating "events", the JSP is not really running. How you phrase that question suggests a lack of understanding about HTTP and the web that has nothing to do with Java. Maybe you understand it fully, and aren't using the correct terms, but it's hard to tell.
Thank you all for your help again. What I am really trying to accomplish is this:
My JSP page opens an object within which a jar file is called (which in turn has the applet). This applet loads on the JSP page and waits for the user to take action (select files for import, and click the import button). I would like my JSP code to know when the user clicks the import button on the applet, after which I would open an image.
I initially thought this can be accomplished without touching the applet code, and just work with JSP's code. After following your responses though, I believe that I will have to modify the applet code for this to work.
1) When the JSP runs, it simply generates HTML, at which point the JSP page's job is done.
2) The HTML gets read by the browser and displayed.
3) The browser sees the object/embed tag and loads the jar file and then runs the applet.
At this point, the applet can certainly connect back to the server. Depending on what you need to do, it may differ. Generally, you will fall into 1 of 2 categories:
1) You just need to move to a new page: In this case, you just call applet.getAppletContext().showDocument() with a URL. That can target a frame or a window, or just replace the contents of the current page (closing the applet). The URL you use can have parameters attached in the standard HTTP GET URL format.
2) You need the applet to load some data: In this case, you use URLConnection to send a request to the server. This can be GET or POST. There's plenty of examples around the forums for either. This will not close the applet, the browser won't see the response, you have to handle everything within the applet itself.
Message was edited by:
bsampieri
