I've been having this nasty little problem. I created a utility to print out various scopes in my app, e.g., tile, page, session, request, application.
I think I have written this same utility several times over the years.....
Here it is..... (maybe I wont loose it this time)....
/*
* Created on Jul 2, 2003
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package util;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.JspException;
import org.apache.struts.taglib.tiles.ComponentConstants;
import org.apache.struts.tiles.ComponentContext;
import java.io.IOException;
/**
* @author rhightower
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class DebugUtil {
public static void listScope(PageContext context, int scope) throws JspException, IOException{
JspWriter out = context.getOut();
switch (scope){
case PageContext.PAGE_SCOPE :
out.println("--- Page Attributes ---
");
break;
case PageContext.REQUEST_SCOPE :
out.println("--- Request Attributes ---
");
break;
case PageContext.SESSION_SCOPE :
out.println("--- SESSION Attributes ---
");
break;
case PageContext.APPLICATION_SCOPE :
out.println("--- APPLICATION Attributes ---
");
break;
}
Enumeration enums = context.getAttributeNamesInScope(scope);
while(enums.hasMoreElements()){
String name = (String)enums.nextElement();
Object value = context.getAttribute(name, scope);
printNameValueType(name, value, out);
}
out.println("---------------------------
");
}
private static void printNameValueType(String name, Object value, JspWriter out) throws IOException{
out.println(name + " = " + value
+ " type (" + value.getClass().getName()+ ") " +
"
");
}
public static void listParameters(PageContext context)throws JspException, IOException{
JspWriter out = context.getOut();
Map map = context.getRequest().getParameterMap();
Iterator iter = map.entrySet().iterator();
out.println("--- Request Parameters ---
");
while (iter.hasNext()){
Map.Entry next = (Map.Entry) iter.next();
if (next.getValue() instanceof String){
out.println(next.getKey() + " = " + next.getValue() + "
");
}
else if (next.getValue() instanceof String[]){
StringBuffer buf = new StringBuffer(100);
String[] values = (String[])next.getValue();
buf.append("{");
for (int index = 0; index < values.length; index++){
buf.append(values[index]);
buf.append(",");
}
buf.append("}");
out.println(next.getKey() + " = " + buf.toString() + "
");
}
}
out.println("--------------------------
");
}
public static void listTileScope(PageContext context) throws JspException, IOException {
JspWriter out = context.getOut();
ComponentContext compContext = (ComponentContext)context.getAttribute( ComponentConstants.COMPONENT_CONTEXT, PageContext.REQUEST_SCOPE);
out.println("--- TILE Attributes ---
");
if (compContext!=null){
Iterator iter = compContext.getAttributeNames();
while(iter.hasNext()){
String name = (String)iter.next();
Object value = compContext.getAttribute(name);
printNameValueType(name, value, out);
}
}else{
out.println("--- TILE Attributes NOT FOUND ---
");
}
out.println("---------------------------
");
}
public static void debug(PageContext context) throws JspException, IOException{
JspWriter out = context.getOut();
out.println("
--------------------------
");
out.println("---------D----------------
");
out.println("----------E---------------
");
out.println("-----------B--------------
");
out.println("------------U-------------
");
out.println("-------------G------------
");
out.println("--------------------------
");
listTileScope(context);
listScope(context, PageContext.PAGE_SCOPE);
listScope(context, PageContext.REQUEST_SCOPE);
listScope(context, PageContext.SESSION_SCOPE);
listScope(context, PageContext.APPLICATION_SCOPE);
listParameters(context);
}
}