java代码:
Map<String,String> user = new HashMap<String,String>();
user.put("ID1","VALUE1");
user.put("ID2","VALUE2");
user.put("ID3","VALUE3");
model.addAttribute("userInfo",user);
jsp代码1:
<c:set var="result" value="<%=list.get(0).getdataSource()%>"> ---从DB取到的一个字符串:userInfo
<c:set var="index" value="<%=param.get(0).getName()%>">------String类型key 值:ID2
<input type="text" value="${result[index] }">
jsp代码2:
<c:set var="index" value="<%=param.get(0).getName()%>">------String类型key 值:ID2
<input type="text" value="${userInfo[index] }">
代码1的结果:
出现下面异常【Property 'ID2' not found on type java.lang.String】
怎么处理才能正常取到结果[VALUE2]呢?
代码2的结果:
[VALUE2]能正常获取到。