tags:

views:

62

answers:

2

Is there a way to invoke a local program in JSP?

for example, to add a button to a jsp page, and when the user press the button the windows calculator app will be opened.

Thanks

A: 

If you want to launch the program on the client's machine, you're looking at JavaScript or some other client-side script, not JSP which is server-side.

And no, there is no reliable way of launching applications on the client machine from the browser, by design. Allowing this would pose a massive security risk.

There are some IE-specific ways of launching programs, but it's never a good idea. I believe the default security settings in IE will prevent this from working anyways: http://www.tutorial5.com/content/view/51/45/

meagar
+1  A: 

To clear a misconception: JSP is a server side view technology which runs at the server machine, produces a bunch of HTML/CSS/JS based on the template content and any taglibs and EL and sends it as one big string over network to the client side. The webbrowser which runs at the client side will in turn interpret/apply/execute the HTML/CSS/JS accordingly. Rightclick page in webbrowser and choose View Source. If JSP has done its task well, you shouldn't see any line of Java/JSP/EL code.

The only way to achieve this particular functional requirement is to let the JSP page serve up an embedded (and signed!) applet or webstart application which is to be downloaded (automatically) by the client machine and in turn does something like:

Runtime.getRuntime().exec("calc.exe");

You only need to realize that this is going to become platform specific and thus ain't going to work for webpage visitors running for example Mac or Linux. You'll either need to add some additional checks based on System.getProperty("os.name") and so on, or to forget the idea and look in a different corner for the solution.

BalusC