This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Executing java file in HTML-page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Executing java file in HTML-page" Watch "Executing java file in HTML-page" New topic

Executing java file in HTML-page

Simon Kaali

Joined: Jun 26, 2002
Posts: 3
Hi gurus,
Is it possible to execute a .java or .jar or .exe file from HTML-page (with javascript?)? How?
My purpose is to start a little java program when the button or link is clicked in HTML page.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347

are you talking about an applet that runs on the client? or something that runs on the server?

Visit my download page
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347

well the basic answer is yes for .class or .jar. how you do it depends on if you do it on the client (applet) or, if your server supports java, on the server (JSP or servlets). i believe you can run .exe using cgi. .java would have to be compiled first
for an applet, you can just load a different page containing the applet when the button or link is clicked. i've done that before. no javascript necessary if a link. for a button i used onclick

<input type='button' value='Sure, why not!' on_Click=\"top.frames[1].location=''\">

(code looks a little strange because it is really part of a servlet)
(wish i could remember what the backslashes were for)
(had to add underscore for the forum to accept my post)
i had 2 buttons or i could have used <form action="URL"><input type="submit">
[ June 28, 2002: Message edited by: Randall Twede ]
[ June 28, 2002: Message edited by: Randall Twede ]
[ June 28, 2002: Message edited by: Randall Twede ]
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
I dont really understand what are you trying to do, but there is some "related" information:
if this program, that you want to start, located on a client machine, for IE you could use:
var w = new ActiveXObject('WScript.Shell');
for NS you could use LiveConnect, and execute almost any Java code directly from JavaScript.
For both cases script should be allowed by user to do that.
If it is located a server, but you want it to run on client machine:
I never did it in NS, but in IE, if your link will point to .exe file (and for most others extension) user will choose between "Open" which will run a program and "Save". I guess in NS it something simylar.
Have you checked out Aspose?
subject: Executing java file in HTML-page
It's not a secret anymore!