簡體   English   中英

在Struts2 JSP中獲取Map的價值

[英]Getting the value of a Map in Struts2 JSP

我在應用程序/服務器啟動期間將值的映射加載到ServletContext中

HashMap<String, List<String>> cfsUfsMap = new HashMap<String, List<String>>();
//some operations
application.setAttribute("UDM_UFS_CFS_MAP", cfsUfsMap); //application = ServletContext

我需要直接在JSP頁面中使用此地圖,為此

<s:set name="udm_cfs_ufs_map" value="#application.UDM_UFS_CFS_MAP" />
<table class="first" width="100%" border="0" cellpadding="0" id="sups_assignedservices_info_table">
<tr>
    <th width="30%">Assigned service name </th>
    <th width="15%">CFS Code </th>
    <th width="15%">Status </th>
    <th width="20%">Date </th>
    <th width="20%">UDM </th>
</tr>
<s:iterator value="#sups_services.services">
    <s:set name="ufs_list" value="#udm_cfs_ufs_map.['top.code']" /> 
    <tr>                
        <td class="light"><s:property value="top.name"/> </td>
        <td class="light"><s:property value="top.code"/> </td>
        <td class="light"><s:property value="top.status"/> </td>
        <td class="light"><s:property value="top.date"/> </td>  
        <td class="light"><s:property value="#udm_cfs_ufs_map.size()" /> - <s:property value="#ufs_list.size()" /></td>
    </tr>   
</s:iterator>

如您所見,我正在嘗試使用top.code的鍵從地圖中獲取值(List),但是我正在獲取原始地圖大小,而不是基於鍵的列表大小。

任何想法都丟失/出了什么問題

完成。

我自己解決了。 我正在發布我的錯誤和正確的解決方案。 所以線下可能對某人有用

訪問ServletContext屬性

<s:set name="udm_cfs_ufs_map" value="#application.UDM_UFS_CFS_MAP" />

用於根據密鑰從地圖中獲取內容

<s:iterator value="#sups_services.services">
<s:set name="ufs_list" value="#udm_cfs_ufs_map[top.code]" />
<tr>
    <td class="light"><s:property value="top.name" /></td>
    <td class="light"><s:property value="top.code" /></td>
    <td class="light"><s:property value="top.status" />
    </td>
    <td class="light"><s:property value="top.date" /></td>
    <td class="light"><s:iterator value="ufs_list">
            <s:property />
            <br />
        </s:iterator></td>
</tr>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM