用Struts2在页面上遍历两个集合.一个是list一个是Map我要怎么区分遍历?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用Struts2在页面上遍历两个集合.一个是list一个是Map我要怎么区分遍历?相关的知识,希望对你有一定的参考价值。

用foreach遍历。list是用下标,map是用键值对。希望能帮到您。
假如你List里封装的是实体类,转发到页面后,你可以在页面这样:
<s:iterator value="list">
<s:property value="list里的属性" />
<s:property value="list里的属性" />
</s:iterator>
假如是Map,转发到页面后,你可以在页面这样:
<s:iterator value="list">
<s:property value="key" />
<s:property value="value.属性" />
</s:iterator>
这些方法灵活运用就OK
有不懂的在追问
参考技术A list太easy了吧,map是以键值对的方式保存数据,遍历后,取值是根据key和value来取值的,我写个简单的例子你看看,把这个写在action里,Map<String,Object> map=new HashMap<String,Object>();
List<String> list=new ArrayList<String>();
map.put("aaa","aaa1");
map.put("bbb","bbb1");
list.add("ccc");
list.add("ddd");
ServletActionContext.getRequest().setAttribute("map",map);
ServletActionContext.getRequest().setAttribute("list",list);下面这些写在你要遍历的集合的jsp页面<s:iterator value="#request.map">
<s:property value="key" />
<s:property value="value" />
</s:iterator>key就可取到map里所有的键,aaa和bbbvalue可以取到map所有的值,aaa1和bbb1

vbscript 它是一个脚本定位器,​​用于评估两个备选集合的接近程度,并从第二个lis返回一系列备选方案

Private Sub ScrRelations_LocateAlternatives(ByVal pXDoc As CASCADELib.CscXDocument, ByVal pLocator As CASCADELib.CscXDocField)
   Dim oAlts1 As CscXDocFieldAlternatives
   Dim oAlts2 As CscXDocFieldAlternatives
   Dim arrAlts() As CscXDocFieldAlternative
   Dim oAlt As CscXDocFieldAlternative
   Dim oNewAlt As CscXDocFieldAlternative
   Dim i As Long

   Set oAlts1 = pXDoc.Locators.ItemByName("FmtCrownAgents").Alternatives
   Set oAlts2 = pXDoc.Locators.ItemByName("FmtNumbers").Alternatives
   arrAlts = EvaluateAlternativesRelationships(oAlts1, oAlts2, 1, 10)

   For i = LBound(arrAlts) To UBound(arrAlts)
      Set oAlt = arrAlts(i)

      If oAlt Is Nothing Then
         Exit For
      End If

      Set oNewAlt = pLocator.Alternatives.Create()
      oNewAlt.Confidence = oAlt.Confidence
      oNewAlt.Height = oAlt.Height
      oNewAlt.Left = oAlt.Left
      oNewAlt.Text = oAlt.Text
      oNewAlt.Top = oAlt.Top
      oNewAlt.Width = oAlt.Width
   Next
End Sub

Private Function EvaluateAlternativesRelationships(ByVal alts1 As CscXDocFieldAlternatives, ByVal alts2 As CscXDocFieldAlternatives, _
                                                   ByVal minLineDistance As Long, ByVal maxLineDistance As Long) As CscXDocFieldAlternative()
   Dim i As Long
   Dim j As Long
   Dim lAltsIndex As Long
   Dim arrAlts() As CscXDocFieldAlternative
   Dim oAlt1 As CscXDocFieldAlternative
   Dim oAlt2 As CscXDocFieldAlternative
   Dim lAlt1Line As Long
   Dim lAlt2Line As Long
   Dim lLineDistance As Long

   ReDim arrAlts(99)
   lAltsIndex = -1

   For i = 0 To alts1.Count - 1
      Set oAlt1 = alts1.ItemByIndex(i)

      If oAlt1.Words.Count > 0 Then
         lAlt1Line = oAlt1.Words.ItemByIndex(0).LineIndex

         For j = 0 To alts2.Count - 1
            Set oAlt2 = alts2(j)

            If oAlt2.Words.Count > 0 Then
               lAlt2Line = oAlt2.Words.ItemByIndex(0).LineIndex
               lLineDistance = lAlt2Line - lAlt1Line

               If lLineDistance >= minLineDistance And lLineDistance <= maxLineDistance Then
                  lAltsIndex = lAltsIndex + 1

                  If lAltsIndex > UBound(arrAlts) Then
                     ReDim Preserve arrAlts(UBound(arrAlts) + 99)
                  End If

                  Set arrAlts(lAltsIndex) = oAlt2
               End If
            End If
         Next
      End If
   Next

   If lAltsIndex > -1 And lAltsIndex < UBound(arrAlts) Then
      ReDim Preserve arrAlts(lAltsIndex)
   End If

   EvaluateAlternativesRelationships = arrAlts
End Function

以上是关于用Struts2在页面上遍历两个集合.一个是list一个是Map我要怎么区分遍历?的主要内容,如果未能解决你的问题,请参考以下文章

struts2标签中在jsp页面如何给值栈中的list和map赋值

用struts2标签如何从数据库获取数据并在查询页面显示。最近做一个小项目,需要用到struts2标签从数据库查询数据,并且用迭代器iterator标签在查询页面显示,可是一开始,怎么也获取不到数据,

jsp加载时怎么获取后台list集合并遍历

用struts2标签在jsp页面中取得list的第一个元素

使用Struts2标签遍历集合

html页面上如何遍历集合