Skip to content

Instantly share code, notes, and snippets.

@ZuluagaSD
Created October 5, 2012 17:23
Show Gist options
  • Save ZuluagaSD/3841143 to your computer and use it in GitHub Desktop.
Save ZuluagaSD/3841143 to your computer and use it in GitHub Desktop.
@WebServlet(name = "Principal", urlPatterns = {"/Principal"})
public class Principal extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String user = request.getParameter("user");
String pass = request.getParameter("pass");
String ip = request.getParameter("ip");
PrincipalDAO principalDAO = new PrincipalDAO();
// ArrayList<String[]> resultArr = principalDAO.Connect(user, pass, ip);
// Testing
ArrayList<String[]> resultArr = new ArrayList<String[]>();
String[] a = {"SCMPRB013MDE", "poweredOn", "running", "Microsoft Windows Server 2003 (32-bit)", "172.26.1.29", "SCMPRB013MDE.ads.loc", "2", "2", "1", "Colcafe_MES",};
String[] b = {"SCMADS023MDE", "poweredOn", "notRunning", "Microsoft Windows Server 2008 R2 (64-bit)", "null", "null", "4", "1", "1", "Infraestructura_1",};
String[] c = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10",};
resultArr.add(a);
resultArr.add(b);
resultArr.add(c);
PrintWriter pout = response.getWriter();
pout.print("<h1>I´ve found: " + resultArr.size() + " Virtual Machines</h1>");
pout.print("<table border='1' style=''><tr>");
pout.print("<th>#</th>");
pout.print("<th>Virtual Machine Name:</th>");
pout.print("<th>Status:</th>");
pout.print("<th>VMWare Tools State:</th>");
pout.print("<th>Operating System</th>");
pout.print("<th>IP Address:</th>");
pout.print("<th>Host:</th>");
pout.print("<th>Memory in GB:</th>");
pout.print("<th>Number of Cores:</th>");
pout.print("<th>Number of Data Stores:</th>");
pout.print("<th>Number</th>");
pout.print("</tr>");
for (int i = 0; i < resultArr.size(); i++) {
pout.print("<tr>");
pout.print("<td>" + (i + 1) + "</td>");
for (int j = 0; j < 10; j++) {
pout.print("<td>" + resultArr.get(i)[j] + "</td>");
}
pout.print("</tr>");
}
pout.print("</table>");
pout.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
@jvelezpo
Copy link

jvelezpo commented Oct 5, 2012

change this
pout.print("" + resultArr.get(i)[0] + "");
pout.print("" + resultArr.get(i)[1] + "");
pout.print("" + resultArr.get(i)[2] + "");
pout.print("" + resultArr.get(i)[3] + "");
pout.print("" + resultArr.get(i)[4] + "");
pout.print("" + resultArr.get(i)[5] + "");
pout.print("" + resultArr.get(i)[6] + "");
pout.print("" + resultArr.get(i)[7] + "");
pout.print("" + resultArr.get(i)[8] + "");
pout.print("" + resultArr.get(i)[9] + "");

to this
for(int j = 0; j < resultArr.lenght; j++){
pout.print("" + resultArr.get(i)[j] + "");
}

@jvelezpo
Copy link

jvelezpo commented Oct 5, 2012

resultArr.get(i).length

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment