Using JSTL how to “put” a value into a HashMap

旧巷老猫 提交于 2019-12-21 11:33:09

问题


I'm looking to set the key value pairing of a HashMap using JSTL only. Is this possible?

I know how to retrieve the key value pairs, but I haven't found a way to set them.

Any help would be appreciated.

Example of retrieving HashMap key/value pairs using JSTL:

<c:forEach var="hash" items="${myHashMap}">             
    <c:out value="${hash.key}" />
    <c:out value="${hash.value}" />
...

回答1:


You can use the <c:set>.

<c:set target="${myHashMap}" property="key" value="value"/> 



回答2:


I wouldn't use JSTL to do that, but straight-up JSP will get it done...

<%
myHashMap.put("hello", "world");
%>


来源:https://stackoverflow.com/questions/8750213/using-jstl-how-to-put-a-value-into-a-hashmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!