简体   繁体   中英

How to run jar file from JSP?

When I am going to click on button, I want to execute jar file which is on server.
Is it possible to execute jar file onClick event of button?


Note: Jar is on server. Jar functionality is that, it edit some files which are in client machine .

Executing a jar is nothing but calling main method of the Main-class of the jar you can simply cal it from your servlet and on click post the request to servlet to execute that jar..

if it is client side you need to go with applet

Well, theoretically you can, but you should have an idea of what all this implies. If you add a "button" into your JSP page, like some Javascript widget or an <input type=button"/> all this will arrive in the user's browser as HTML code. When the guy clicks it or does something in that HTML page (which was generated by the JSP) all you (the developer) can do with it is send it asan HTTP command back to the server (like when he clicks the button you can call the link http://myServerAddress:8080/myUrl ). Now in the servlet or whatever dynamic component you have answering for that URL you can do whatever you want, load a jar file, call some method from some class inside that jar, you can even use the Runtime to execute an OS command (tho that would no longer make your app OS agnostic) like , "java -jar myJar.jar". Then you can return the response of that execution/call back to the user by either sending back the console output, or redirecting/forwarding him to a different page, etc.

You would need to handle the JavaScript onclick and send a http call to a jsp that executes a jar. Assuming your jar is executable.

You can use Ajax or a page request from JavaScript.

Jar functionality is that, it edit some files which are in client machine.

That would require either an applet or an app. launched using Java Web Start .

Further, either of those would need to be either of:

  1. Digitally signed by the developer, and trusted by the end user.
  2. Sand-boxed and using the JNLP API services to access the local file-system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM