简体   繁体   English

jsp中嵌套表达式(el)的用法

[英]usage of nested expression(el) in jsp

learning jsps. 学习jsps。 got doubt on nested expression. 对嵌套表达式有疑问。 i create a list and map in servlet, add it to the request attributes and dispatch it to jsp. 我创建一个列表并在servlet中进行映射,将其添加到请求属性中并将其分派到jsp。 in the jsp i'm just trying to read the values. 在jsp中,我只是想读取值。

setting attributes in servlet: 在servlet中设置属性:

    List<String> someList = new ArrayList<String>();
    someList.add("one");someList.add("two");someList.add("three");
    Map<String,Integer> m = new HashMap<String,Integer>();
    m.put("one", 1);
    m.put("two", 2);
    m.put("three", 3);
    req.setAttribute("someList",someList);
    req.setAttribute("hmap", m);

jsp code: jsp代码:

<body>
    <br> list : ${someList}
    <br>
    <br> map:${hmap}
    <br />
    <br> using JSTL: ${hmap["${someList['0']}"]} is the value for key
    ${someList["0"]}
    <br />
    <br /> USING hardocded ${hmap["one"]} is the value for key one
    <br />
</body>

html output HTML输出

list : [one, two, three] 

map:{two=2, one=1, three=3} 

using JSTL: is the value for key one 

USING hardocded 1 is the value for key one 

why am i getting empty space using nested jstl: ${hmap["${someList['0']}"]}, is it the right way ? 为什么我使用嵌套的jstl获得空的空间:$ {hmap [“ $ {someList ['0']}”]]},这是正确的方法吗?

尝试这个:

${hmap[someList["0"]]} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM