package my.application.helloWorld;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class HelloWorldServlet
*/
@WebServlet("/HelloWorldServlet")
public class HelloWorldServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public HelloWorldServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// response.getOutputStream().println("Hello World at " + (new
// Date()).toString());
try {
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("ls");
BufferedReader input = new BufferedReader(new InputStreamReader(
pr.getInputStream()));
String line = null;
response.getOutputStream().println("Hellow World!");
while ((line = input.readLine()) != null) {
response.getOutputStream().println(line);
}
int exitVal = pr.waitFor();
response.getOutputStream().println("This is Exited with error code " + exitVal);
} catch (Exception e) {
response.getOutputStream().println(e.toString());
e.printStackTrace();
}
}
public static void executeShellCommand( String command ) throws InterruptedException, IOException {
Runtime.getRuntime().exec( command.split( " " ) ).waitFor();
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
No comments:
Post a Comment