//方法一:通过遍历的方法进行遍历 String FileName=""; HttpSession session=request.getSession();//获取session Object name=session.getAttribute("AddFileName"); System.out.println(name); Enumeration enumeration =session.getAttributeNames();//获取session中所有的键值对 //遍历enumeration中的键值对 String[] names=session.getValueNames(); for(int i=0;i<names.length;i++){ if(names[i].equals("AddFileName")){ FileName+=session.getValue(names[i])+"@"; System.out.println(FileName); } }
String FileName="";
//方法二:通过for循环进行遍历 while(enumeration.hasMoreElements()){ String AddFileName=enumeration.nextElement().toString();//获取session中的键值 String value=(String)session.getAttribute(AddFileName);//根据键值取出session中的值 System.out.println(value); FileName+=value+"@"; System.out.println(FileName); //String FileName= (String)session.getAttribute("AddFileName"); }
Stay hungry,stay foolish !