在JSP中的循环内连接字符串 [英] Concatenate of a string within a loop in JSP

查看:165
本文介绍了在JSP中的循环内连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

${x}="mit"

${Place['name_mit']}将结果显示为美国.

但是,如果我尝试${Place['name_'+x]},则会出错.

But if I try ${Place['name_'+x]} I get error.

该如何解决?

推荐答案

是的,它无法编译,因为+运算符未用于字符串混叠(在EL 3.0,Java EE 7之前).
只需使用concat

Yes, it fails to compile as + operator is not used for string concatination (before EL 3.0, Java EE 7).
Just use concat

${Place['name_'.concat(x)]}


从Expression Language 3.0,
使用+运算符连接两个字符串是有效的.


From Expression Language 3.0,
It is valid to use + operator for concatenation of two strings.

${Place['name_'+x]}  //valid as of EL 3.0

来自 EL 3.0规范

字符串连接运算符

要评估

A += B 

  • 将A和B强制转换为字符串.
  • 返回A和B的串联字符串.
  • 这篇关于在JSP中的循环内连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆