tags:

views:

179

answers:

2

Hi,

Is there anything similar to php's exec() function in jsp?

I'm running Websphere App server in my Windows machine. I would like to call some .exe files when a link is clicked in my jsp page.

Please tell me if any function is available in jsp that helps in executing an external program.

A: 

JSPs can effectively do anything Java can do - Java can exec an external program.

You can use

 <%
     // some Java here
 %>
djna
Thanks! I should've thought that!
whoopy_whale
A: 

here you are :

Runtime rt=Runtime.getRuntime();
String cmd[]={"cmd.exe", "/C", "c:\\windows\\paint.exe"};
rt.exec(cmd);
Adinochestva
If you must use Runtime.exec, please do read this: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html. You'll save yourself a lot of heartache.
duffymo
This is probably a very bad idea. I don't have to know much about what you're doing to advise that you reconsider. JSPs are for view, not for calling executable code somewhere on the app server.
duffymo
Ok, I'm using JSP's for view only...I want to summarize the tasks that I execute via command line by providing links/buttons in the jsp page. I dont really want to see the output of the execution, just that I need to call the command line multiple times with different parameters. SO I thought I'll build a Servlet and generate the required parametrs and call the command line. Is it a bad idea?
whoopy_whale