java - 在 Struts2 JSP 中获取 Map 的值

标签 java jsp servlets dictionary struts2

我在应用程序/服务器启动期间将值映射加载到 ServletContext

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

我需要直接在JSP页面中使用这个 map ,我已经这样做了

<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 键从 map 中获取值(列表) 不过,我得到的是原始 map 大小,但不是基于键的列表大小。

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

最佳答案

完成。

我自己解决了。我把我的错误和正确的解决方案贴出来。因此,它可能对某人有用

访问 servletContext 属性

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

用于根据键从 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>

关于java - 在 Struts2 JSP 中获取 Map 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13115950/

相关文章:

java - 在 RxJava/RxAndroid 中的可观察对象之间传递响应

java - WhatsApp 如何检测联系人列表中的谁使用了该应用程序?

java - JSP 和 Servlet socketinput 异常

java - 如何在将 servlet 转发到 jsp 页面后更改 url?

java - 使用数据报进行简单的客户端/服务器聊天数据包路由

java - 在 java (JSP) 中提取 .tar.gz 文件

java - 如何在 jsp 页面中访问我在 servlet 类中声明的自定义对象

java servlet 使用角色登录

servlets - Servlet 过滤器不适用于容器管理的登录页面

java - ycsb加载数据到redis找不到数据