Java中遍历 Session 和 Request
转:
session的遍历:
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)); }
request的遍历:
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; }