Request Attributes")
.attribute("COLSPAN","2")
.left();
Enumeration a = request.getAttributeNames();
while (a.hasMoreElements())
{
name=(String)a.nextElement();
table.newRow();
table.addHeading(name+": ")
.cell().attribute("VALIGN","TOP").right();
table.addCell("" +
toString(request.getAttribute(name))
+ "
");
}
table.newRow();
table.newHeading()
.cell().nest(new Font(2,true))
.add("
Servlet InitParameters")
.attribute("COLSPAN","2")
.left();
a = getInitParameterNames();
while (a.hasMoreElements())
{
name=(String)a.nextElement();
table.newRow();
table.addHeading(name+": ")
.cell().attribute("VALIGN","TOP").right();
table.addCell("" +
toString(getInitParameter(name))
+ "
");
}
table.newRow();
table.newHeading()
.cell().nest(new Font(2,true))
.add("
Context InitParameters")
.attribute("COLSPAN","2")
.left();
a = getServletContext().getInitParameterNames();
while (a.hasMoreElements())
{
name=(String)a.nextElement();
table.newRow();
table.addHeading(name+": ")
.cell().attribute("VALIGN","TOP").right();
table.addCell("" +
toString(getServletContext()
.getInitParameter(name))
+ "
");
}
table.newRow();
table.newHeading()
.cell().nest(new Font(2,true))
.add("
Context Attributes")
.attribute("COLSPAN","2")
.left();
a = getServletContext().getAttributeNames();
while (a.hasMoreElements())
{
name=(String)a.nextElement();
table.newRow();
table.addHeading(name+": ")
.cell().attribute("VALIGN","TOP").right();
table.addCell("" +
toString(getServletContext()
.getAttribute(name))
+ "
");
}
if (request.getContentType()!=null &&
request.getContentType().startsWith("multipart/form-data") &&
request.getContentLength()<1000000)
{
MultiPartRequest multi = new MultiPartRequest(request);
String[] parts = multi.getPartNames();
table.newRow();
table.newHeading()
.cell().nest(new Font(2,true))
.add("
Multi-part content")
.attribute("COLSPAN","2")
.left();
for (int p=0;p" +
multi.getString(parts[p]) +
"");
}
}
String res=request.getParameter("resource");
if (res!=null && res.length()>0)
{
table.newRow();
table.newHeading()
.cell().nest(new Font(2,true))
.add("
Get Resource: "+res)
.attribute("COLSPAN","2")
.left();
table.newRow();
table.addHeading("this.getClass(): ").cell().right();
table.addCell(""+this.getClass().getResource(res));
table.newRow();
table.addHeading("this.getClass().getClassLoader(): ").cell().right();
table.addCell(""+this.getClass().getClassLoader().getResource(res));
table.newRow();
table.addHeading("Thread.currentThread().getContextClassLoader(): ").cell().right();
table.addCell(""+Thread.currentThread().getContextClassLoader().getResource(res));
table.newRow();
table.addHeading("getServletContext(): ").cell().right();
table.addCell(""+getServletContext().getResource(res));
}
page.add(Break.para);
page.add(new Heading(1,"Form to generate Dump content"));
TableForm tf = new TableForm(response.encodeURL(request.getRequestURI()));
tf.method("POST");
tf.addTextField("TextField","TextField",20,"value");
Select select = tf.addSelect("Select","Select",true,3);
select.add("ValueA");
select.add("ValueB1,ValueB2");
select.add("ValueC");
tf.addButton("Action","Submit");
page.add(tf);
page.add(new Heading(1,"Form to upload content"));
tf = new TableForm(response.encodeURL(request.getRequestURI()));
tf.method("POST");
tf.attribute("enctype","multipart/form-data");
tf.addFileField("file","file");
tf.addButton("Upload","Upload");
page.add(tf);
page.add(new Heading(1,"Form to get Resource"));
tf = new TableForm(response.encodeURL(request.getRequestURI()));
tf.method("POST");
tf.addTextField("resource","resource",20,"");
tf.addButton("Action","getResource");
page.add(tf);
}
catch (Exception e)
{
Code.warning(e);
}
page.write(pout);
String data=request.getParameter("data");
if (data!=null && data.length()>0)
{
int d = Integer.parseInt(data);
while (d>0)
{
pout.println("1234567890123456789012345678901234567890123456789\n");
d=d-50;
}
}
pout.close();
if (pi!=null)
{
if ("/ex4".equals(pi))
throw new ServletException("test ex4",new Throwable());
if ("/ex5".equals(pi))
throw new IOException("test ex5");
if ("/ex6".equals(pi))
throw new UnavailableException("test ex6");
if ("/ex7".equals(pi))
throw new HttpException(501);
}
}
/* ------------------------------------------------------------ */
public String getServletInfo()
{
return "Dump Servlet";
}
/* ------------------------------------------------------------ */
public synchronized void destroy()
{
Code.debug("Destroyed");
}
/* ------------------------------------------------------------ */
private static String toString(Object o)
{
if (o == null)
return null;
if (o.getClass().isArray())
{
StringBuffer sb = new StringBuffer();
Object[] array = (Object[]) o;
for (int i=0; i 0)
sb.append("\n");
sb.append(array.getClass().getComponentType().getName());
sb.append("[");
sb.append(i);
sb.append("]=");
sb.append(toString(array[i]));
}
return sb.toString();
}
else
return o.toString();
}
}