1

我在应用程序/服务器启动期间将值映射加载到 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 的键从地图中获取值(列表)但是我得到的是原始地图大小,而不是基于键的列表大小。

知道缺少什么/出了什么问题

4

1 回答 1

1

Done.

I solved it myself. I am posting my mistakes and the correct solution. SO down the line it might be useful to someone

to access servletContext attributes

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

for fetching the content from the map based on key

<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>

于 2012-10-29T05:30:52.893 回答