• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to run any file from jsp  RSS feed

 
chbharath Kumar
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!