• 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

executing a file on server using servlet?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am trying to compile a java file on server
using the following servlet. I am using
Process proc=runtime.exec("C:\\j2sdk1.4.1_01\\bin\\javac HelloServlet.java"); I am compiling the code succesfully
and when i call the servlet at browser it displays HELLO
but not compiling the given file. I am using Tomcat and windows NT.
here is the servlet code ....please help.........
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Hello extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" +
"</BODY></HTML>");

try
{
Runtime runtime=Runtime.getRuntime();
Process proc=runtime.exec("C:\\j2sdk1.4.1_01 \\bin\\javac HelloServlet.java");
BufferedReader br=new BufferedReader(new InputStreamReader(proc.getInputStream()));
PrintWriter com_out=response.getWriter();
com_out.println("<pre>");
String line=null;
while((line=br.readLine())!=null)
{ com_out.println(line);
}
}
catch (Exception e)
{
out.println("Listener *not* started!");
}

}
}
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Process proc=runtime.exec("C:\\j2sdk1.4.1_01\\bin\\javac HelloServlet.java");
/*wait untill command is executed*/
int exitVal = proc.waitFor();
if( exitVal == 0)
{
System.out.println("Sucess");
}
else
{
System.out.println("Failed");
}
I do not know what exactly each code means. Just know that 0 is successful execution.
All the best.
-Minu.
[ March 18, 2003: Message edited by: Mrinalini Gudi ]
reply
    Bookmark Topic Watch Topic
  • New Topic