The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
January 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Calling a .exe file from a remote server !!

Posted by shams on February 12, 2001 at 1:10 AM

I have a .exe file on my server which I want to call and run on a clients machine through a servlet. I am able to call a normal .exe file thru this but when I run my actual .exe file which is dependent on some .dll files it gives me error that .dll file not found. I have even tried usinng the Runtime class but then the file opens on the server side only Below is my coding:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class filedownload extends HttpServlet
{
public void doPost(HttpServletRequest sReq ,HttpServletResponse sRes)
throws IOException,ServletException
{

String fileWanted="nowork.exe"
String pathOfFile = "c:/"+ "Downloadablefiles"+"\\" + fileWanted;

File F = new File(pathOfFile);
sRes.setContentType("application/x-msword");

//the next statement is the most IMPORTANT statement
sRes.setHeader("Content-Disposition", "attachment;filename=\"" + fileWanted +"\"");

ServletOutputStream out = sRes.getOutputStream();
InputStream in = null;
try
{
in = new BufferedInputStream(new FileInputStream(F));
int ch;
while ((ch = in.read()) !=-1)
{
out.print((char)ch);
}
}
catch(Exception e)

{
System.out.println(e.toString());
}

finally
{
if (in != null) in.close();
}


}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us