Java Reference
In-Depth Information
ArrayList<Object> accounts=dao.getAcctDetails();
int acctNum;
String acctName;
fl oat balance;
String formattedBalance;
fi nal int NUM_FIELDS = 3;
for (int i=0; i<accounts.size()/NUM_FIELDS; i++)
{
acctNum =
(Integer)accounts.get(i*NUM_FIELDS);
acctName =
(String)accounts.get(i*NUM_FIELDS+1);
balance =
(Float)accounts.get(i*NUM_FIELDS + 2);
out.println("<TR>");
out.println("<TD>" + acctNum + "</TD>");
out.println("<TD>" + acctName + "</TD>");
formattedBalance =
String.format("%.2f", balance);
out.println("<TD>"+formattedBalance+"</TD>");
out.println("</TR>");
}
out.println("</TABLE>");
out.println("</CENTER>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
dao.close();
}
}
In order to access the above servlet, Tomcat must be started, either by double-
clicking on fi le startup.bat (in <CATALINA_HOME>\bin ) or by entering the fol-
lowing command into an MS DOS command window (assuming that startup.bat is
on the PAT H ):
startup
By default, Tomcat runs on the local machine (identifi ed by the name localhost )
on port 8080. The URL that must be entered into your browser to execute the above
servlet is http://localhost:8080/<WebAppName>/DAOTestServlet (replacing
<WebAppName> with the name of the containing Web application, of course). This
will generate output of the form shown in Fig. 7.7 .
Search WWH ::




Custom Search