/* Code to look at the contents of a directory and print the results as the output sent from the Servlet*/ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class CheckDirectory extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { int value; Process myProcess; Runtime myRuntime; PrintWriter out = response.getWriter(); out.println("Attempting to get runtime"); try{ myRuntime = Runtime.getRuntime(); //myProcess = myRuntime.exec("ls"); //IDEA 1: ls into user's subdirectory and list contents myProcess = myRuntime.exec("ls /staff2/grewe/public_html/comments"); InputStream myIS = myProcess.getInputStream(); //now wait for process out.println("ls finished"); while (( value = myIS.read() ) != -1) { //print out the character not the number value. out.print((char) value); } }catch (Exception e) {out.println(e.getMessage()); } } }