How do I concatenate strings in EL?
I want to do something like this but it doesn’t work:
${var1 == 0 ? 'hi' : 'hello ' + var2}
It throws an exception trying to cast 'hello' to a Double
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
+operator always means numerical addition in JSP Expression Language. To do string concatenation you would have to use multiple adjacent EL expressions like${str1}${str2}.If I read your example correctly this could be written as:
Edit
Another possibility would be to use JSTL, which is longer but might be clearer if there is more text that depends on
var1:The
c:outmight not be needed, depending on the JSP version.