This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes call java (main) program from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "call java (main) program from JSP" Watch "call java (main) program from JSP" New topic

call java (main) program from JSP

prash bhugra

Joined: Jul 25, 2001
Posts: 2
I have a java program, which is supposed to run as a batch. Would like to know how to invoke this batch program from the JSP page.
Thanks in advance.
Bill Siggelkow
Ranch Hand

Joined: Jun 27, 2001
Posts: 57
You use the java.lang.Runtime.getRuntime().exec() call to execute a process on the server. Keep in mind that the JSP simply becomes a servlet that executes on the <b>server</b> not the client. I have had good luck executing a shell script on Unix systems or batch (.bat or .cmd) files in Windows.
However, if you are executing Java, first look into using the exposed Java API (if there is one) of whatever you are doing and running in the same VM with the following warning
<b>Do not call the main method of some Java class from another Java class as often the main method terminates by calling System.exit() which will kill the JVM.</b>

Bill Siggelkow
Jade Cove Solutions
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: call java (main) program from JSP
Similar Threads
How to run dos batch file from java program
how to run batch files from a java program
execute java.class in batch to tun
help regarding batch file
Thread Related Problem