有一个map 
格式如下{AAAAA1=com.dxyt.ybjg.action.SelectIllegal@5bf624, AAAAA2=com.dxyt.ybjg.action.SelectIllegal@1955970}map中的没一个元素是页面中的一条数据,由于一页显示的数据条数有限,我现在想做一个分页,
如果数据达到5条 ,页面等待10秒 显示下一页 。
现在 我想这么做,判断一个map的元素 。如果大于5 我就把前5条元素取出来放到页面中,然后把剩下的 放到session 。在等待10秒的时候从新发送一个action请求。 取出session中的map 数据。放到后一页。我该怎么取出 前map中前5条数据??? 高手指教 谢谢
用的是struts2 框架, freeer是前台页面

解决方案 »

  1.   

    不用放session啊,
    用Ajax取不就可以了。
    先判断总共有多少条,取出5条有剩余,等过10秒继续取。
    如果少于等于5条,那么就取一次。你要放session,如果每个人都来看这页面,那么你服务器不知道要产生多少对象了。
      

  2.   

    恩,关键是怎么取出前5条 。
    按字符串 截取的  可以做 ,但是截取出来的是个string 没法转map
      

  3.   

    你这Map是HashMap? Map map = new HashMap();
            map.put("1", 1);
            map.put("2", 2);
            map.put("3", 3);
            map.put("4", 4);
            map.put("5", 5);
            map.put("6", 6);
            map.put("7", 7);
            map.put("8", 8);
            Iterator itor = map.values().iterator();
            int index = 0;
            while (itor.hasNext())
            {
                Object obj = itor.next();//取出你的值
                System.out.println(obj);
                index++;
                if (index > 5)
                {
                    break;
                }
            }
             运行结果:
    3
    2
    1
    7
    6
    5
    建议,改用List类型
      

  4.   

    if (index > =5)
                {
                    break;
                }
    产生了6个结果了,加个=号就可以了
      

  5.   

    Set<Map.Entry> set =  map.entrySet();
    object[] objs = set.toArray();
    objs中是Map.Entry对象,在数组中就能按顺序取了
      

  6.   

    hash怎么会有顺序
    你去弄treemap吧
      

  7.   

    Map map = new HashMap();
            map.put("1", 1);
            map.put("2", 2);
            map.put("3", 3);
            map.put("4", 4);
            map.put("5", 5);
            map.put("6", 6);
            map.put("7", 7);
            map.put("8", 8);
            Iterator itor = map.values().iterator();
            int index = 0;
            while (itor.hasNext())
            {
                Object obj = itor.next();//取出你的值
                System.out.println(obj);
                index++;
                if (index > 5)
                {
                    break;
                }
            }
            能不能把运行结果 在放在原来的map里面,
      

  8.   

    你可以新建一个map,然后把值放进去。
    建议最好不要用map,用List比较好。
      

  9.   

    Map没有顺序的,楼主用ArrayList吧另外ajax调不错,可以不用session的就不要用session,否则服务器迟早吃不消。