• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to run any file from jsp

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How to run an exe or bat file andalso how to open msword with a specified document using jsp. Can any one please help me.

I tried with the following code but it doesn't give any errors and no output. I am using tomcat5.5.14.

<%@page import="java.util.*,java.text.*,java.io.*"%>
<%

Runtime r = Runtime.getRuntime();
Process p = null;
try
{
p = r.exec("cmd /C C:/windows/NOTEPAD.exe");
}
catch(Exception e)
{
out.println(e.getMessage());
}
%>

----------
Regards,
Bharath kumar.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So many issues related to this...

First, all "problem conditions" in Runtime.exec() do not throw errors - try and get the OutputStream of the Process and see if anything (like an error message) is being printed inside the Process.

Second, Runtime.exec() in a JSP starts up a new process and executes the supplied program on the server - the only thing a JSP should be doing is building a HTML web page. Thus, the only type of Runtime.exec() program that makes sense to call like this would be one that provided some sort of text you wanted to include in a webpage. However -

Third, you would probably *never* want to do this in a "real world" scenario - web pages need to be responsive, starting up a new process and parsing input to/output from it is going to be really slow. Plus, *every time* the page gets called (or at least that portion of the JSP), a new process is started and run - that's going to quickly bog down the server and make the whole thing unresponsive.

What are you trying to accomplish using Runtime.exec() in a JSP page? Unless this is just trying to see if you can do it - there's probably a better way to accomplish what you want...
 
chbharath Kumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am developing a project using JSP and HTML (Java Script). Some other project has excel sheets which contain some Graphical Charts. Now I am trying to link to those excel sheets from my project.
 
And inside of my fortune cookie was this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic