Java 中遍历 Session or Request

java.util.Enumeration   e   =   request.getSession().getAttributeNames(); 
		
while( e.hasMoreElements())   { 
    String sessionName=(String)e.nextElement(); 
    out.println("\nsession item name="+sessionName);
    out.println("\nsession item value="+request.getSession().getAttribute(sessionName));
} 



		
Map map = new HashMap();
map = request.getParameterMap();
for(Iterator iter = map.entrySet().iterator();iter.hasNext();){  
    Map.Entry element = (Map.Entry)iter.next();  
    String strKey = element.getKey().toString(); 
    out.println("\nkey="+strKey);
    String[] value=(String[])element.getValue();
    if(value.length>0){
	 for(int i=0;i<value.length;i++)
out.println("\nvalue"+String.valueOf(i)+"="+value[i].toString());
	  }
    int a=1;
}

你可能感兴趣的:(Web)