如何将HashMap从jsp设置为Action [英] How to Set a HashMap from jsp to Action
问题描述
我的Action类中有一个HashMap:
private Map< String,String> ids = new HashMap< String,String>();
在jsp中,我试图设置这个hashmap:
< input type =textname =ids [0] .keyvalue =key>
< input type =textname =ids [0]value =value>
但是当提交之后,当我在这样的操作中迭代地图时:
$ {pre $ if(ids!= null){
for(Map.Entry< String,String>条目:ids.entrySet()) {
system.out.println(entry.getKey()+ - + entry.getValue());
}
}
我只得到0值而不是键值
我该怎么做我想要的?有人可以帮助我吗?
您的密钥类型为 String
< input type =textname =ids ['0']value =%{value }>
然后您将获得密钥'0'
以及OGNL提供的值。
关于索引属性名称和 createIfNull
设置,您可以在文档< a href =http://struts.apache.org/release/2.3.x/docs/type-conversion.html#TypeConversion-AdvancedTypeConversion =nofollow>高级类型转换。
I have a HashMap in my Action class:
private Map<String, String> ids = new HashMap<String, String>();
In jsp I'm trying to set this hashmap like this:
<input type="text" name="ids[0].key" value="key">
<input type="text" name="ids[0]" value="value">
But when after submit, when I iterate over the map in the action like this:
if(ids!=null){
for(Map.Entry<String, String> entry : ids.entrySet()){
system.out.println(entry.getKey()+"-"+entry.getValue());
}
}
I only get "0-value" instead of "key-value"
How Can I do what I want? Can someone help me with this?
You have keys of type String
and therefore should be mapped like strings. For example
<input type="text" name="ids['0']" value="%{value}">
Then you will get key '0'
and value that was provided by OGNL.
About indexed property names and createIfNull
setting you can find in the docs Advanced Type Conversion.
这篇关于如何将HashMap从jsp设置为Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!