使用struts 2标签迭代jsp中的两个数组 [英] iterate over two arrays in jsp using struts 2 tags

查看:31
本文介绍了使用struts 2标签迭代jsp中的两个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能帮帮我.我的目的是遍历两个 2Dimentional 数组

Can Anyone help me please. My intention is to iterate over the two 2Dimentional arrays

  1. Org_Positions_IdTitle,其中包含 a) 提升位置的 ID 和 b) 它们的标题.
  2. Org_Apps 包含 a) 学生 ID 和 b) 提高​​位置的 ID.
  1. Org_Positions_IdTitle which contains a)the ids of raised positions and b)their Titles.
  2. Org_Apps which contains a)student Ids and b)ids of raised positions.

所以我希望无论何时检查两个数组中的位置 ID 是否等于显示位置的标题.非常感谢你们的帮助.

So I want whenever the position Ids in the two arrays are checked equal to display the Title of the position. Thanks a lot for your help guys.

  ResultSet ResSet_Org_Positions_IdTitle = OrgInfo.Get_Organisation_Positions_IdTitle(username,password);   
            ResultSet ResSet_Org_Apps = OrgInfo.Get_Organisation_Apps(username,password);

        int i=0;
        while(ResSet_Org_Positions_IdTitle.next()){ 
            Org_Positions_IdTitle[i][0] = new String(String.valueOf(ResSet_Org_Positions_IdTitle.getInt("P_Ps_Id")));
            Org_Positions_IdTitle[i][1]= new String(ResSet_Org_Positions_IdTitle.getString("Title")); i++;
            Org_Positions_IdTitle[i][0]= new String("Last");
            //System.out.println(i+":"+Org_Positions_IdTitle[i-1][j-1]+Org_Positions_IdTitle[i-1][j]);
        }

        int m=0; //Org_Apps A_St_Id A_Ps_Id
        while(ResSet_Org_Apps.next()){ 
            Org_Apps[m][0] = new String(String.valueOf(ResSet_Org_Apps.getInt("A_St_Id"))); 
            Org_Apps[m][1]= new String(ResSet_Org_Apps.getString("A_Ps_Id")); m++;
            Org_Apps[m][0]= new String("Last");
            //System.out.println(i+":"+Org_Positions_IdTitle[i-1][j-1]+Org_Positions_IdTitle[i-1][j]);
        }

        session.put("Org_Positions_IdTitle", getOrg_Positions_IdTitle());
        session.put("Org_Apps", getOrg_Apps());



        <s:iterator value="Org_Positions_IdTitle" id="P_Ps_Id" >
            <s:iterator value="Org_Apps" id="A_Ps_Id" >
                <s:if test="%{#P_Ps_Id==#A_Ps_Id} ">
                    <s:property value="Title" />        
                </s:if>
            </s:iterator>
        </s:iterator> 

推荐答案

所以它应该看起来像这样:

So it should look something like that:

<s:iterator value="firstArray" var="arr1">
  <s:iterator value="secondArray" var="arr2">
    <s:if test="#arr1[0] == #arr2[1]">
      <s:property value="#arr1[1]" />        
    </s:if>
  </s:iterator>
</s:iterator>

不要忘记在操作类中需要为数组设置 setter/getter.

Don't forget that you need setters/getters for your arrays in action class.

顺便说一句,Struts2 标签中的 id 属性很久以前就被弃用了,请改用 var.

BTW id attribute in Struts2 tags was deprecated long time ago, use var instead.

还要考虑更改您的代码以使用映射而不是数组.那就不用在JSP上迭代了.

Also consider changing your code to use maps instead of arrays. Then there is no need to iterate it on JSP.

这篇关于使用struts 2标签迭代jsp中的两个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆