Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

param : implicit EL (Expression Language) object in JSP

Tags:

jsp

el

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]}
like image 374
matus Avatar asked Jun 15 '10 14:06

matus


People also ask

What is EL expression in JSP?

Expression Language (EL) in JSP The Expression Language (EL) simplifies the accessibility of data stored in the Java Bean component, and other objects like request, session, application etc. There are many implicit objects, operators and reserve words in EL. It is the newly added feature in JSP technology version 2.0.

Which among the following is are implicit objects of EL in JSP?

The available implicit objects are out, request, config, session, application etc.

What is a expression in JSP <%= %> <% %>?

A JSP expression is used to insert the value of a scripting language expression, converted into a string, into the data stream returned to the client.

Which will enable expression language in JSP?

JSP EL allows you to create expressions both (a) arithmetic and (b) logical. Within a JSP EL expression, you can use integers, floating point numbers, strings, the built-in constants true and false for boolean values, and null.


1 Answers

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]}
like image 182
BalusC Avatar answered Nov 04 '22 16:11

BalusC