Java Tutorial - Java Script :
Testing Tomcat
Enumeration e = request.getParameterNames();
String key = null;
String value = null;
sb.append(makeTitle(“Request Parameters”));
sb.append(“<table>”);
while( e.hasMoreElements() )
{
key = (String)e.nextElement();
value = request.getParameter(key);
sb.append( makeRow( key, value ));
}
sb.append(“</table>”);
return sb.toString();
}
private String showSysProps()
{
StringBuffer sb = new StringBuffer(512);
Properties p = System.getProperties();
Enumeration e = p.propertyNames();
String key = null;
String value = null;
sb.append(makeTitle(“System Properties”));
sb.append(“<table>”);
sb.append(makeRow(“System Time”, today() ));
while( e.hasMoreElements() )
{
key = (String)e.nextElement();
value = p.getProperty( key );
sb.append( makeRow( key, value ));
}
sb.append(“</table>”);
return sb.toString();
}
private String showInitParams()
{
StringBuffer sb = new StringBuffer(512);
ServletContext context = getServletContext();
Enumeration e = context.getInitParameterNames();
Powering the Web Tier with a Server Container 161
String key = null;
String value = null;
sb.append(makeTitle(“Initialization Parameters”));
sb.append(“<table>”);
while( e.hasMoreElements() )
{
key = (String)e.nextElement();
value = context.getInitParameter(key);
sb.append( makeRow( key, value ));
}
sb.append(“</table>”);
return sb.toString();
}
private String showServletContextInfo()
{
StringBuffer sb = new StringBuffer(512);
ServletContext context = getServletContext();
sb.append(makeTitle(“Servlet Context”));
sb.append(“<table>”);
sb.append( makeRow( “Server Info”, context.getServerInfo()));
sb.append( makeRow(
“Servlet Context Name”,
context.getServletContextName()));
sb.append( makeRow( “Real Path”, context.getRealPath(“/”)));
sb.append(“</table>”);
return sb.toString();
}
private String showContextAttributes()
{
StringBuffer sb = new StringBuffer(512);
ServletContext context = getServletContext();
Enumeration e = context.getAttributeNames();
String key = null;
String value = null;
sb.append(makeTitle(“Servlet Context Attributes”));
sb.append(“<table>”);
while( e.hasMoreElements() )
{
key = (String)e.nextElement();
value = context.getAttribute(key).toString();
sb.append( makeRow( key, value ));
}
sb.append(“</table>”);
return sb.toString();
}
private String showSessionAttributes(HttpServletRequest request)
{
StringBuffer sb = new StringBuffer(512);
HttpSession session = request.getSession();
Enumeration e = session.getAttributeNames();
String key = null;
String value = null;
sb.append(makeTitle(“Session Attributes”));
if( session==null )
return “No session attributes”;
sb.append(“<table>”);
while( e.hasMoreElements() )
{
key = (String)e.nextElement();
value = session.getAttribute(key).toString();
sb.append( makeRow( key, value ));
}
sb.append(“</table>”);
return sb.toString();
}
public void doGet(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
out.println(“<html>”);
