param : implicit EL (Expression Language) object in JSP

戏子无情 提交于 2019-12-04 12:14:03

问题


What if I have URL like: servlet.jsp?myparam=myvalue

These 2 ELs should return output "myvalue" , but I actually don't understand why?:

${param.values["myparam"]["0"]}
${param.values.myparam[0]}

回答1:


Where did you get this information from? This won't work in standard JSP 2.1 EL. The correct syntax would be:

${param["myparam"]}
${param.myparam}

In the first example, singlequotes are also allowed and actually more preferred.

${param['myparam']}

It can even be another EL variable in any scope:

${param[myparam]}

Actually, the ${param} refers to a Map<String, String> with only the first param value from the array. In theory, if it was a Map<String, String[]> and the Map class had a getValues() method, then your syntax should work. But it doesn't have, it only has a values() method. Your best bet would then be using ${paramValues} instead which refers to a Map<String, String[]>:

${paramValues['myparam'][0]}
${paramValues.myparam[0]}

or accessing the HttpServletRequest#getParameterMap() directly:

${pageContext.request.parameterMap['myparam'][0]}
${pageContext.request.parameterMap.myparam[0]}


来源:https://stackoverflow.com/questions/3046304/param-implicit-el-expression-language-object-in-jsp

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