Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以在 JSP 中将字符串评估为 EL 表达式并从中获取值?
我需要一个表达式 ${model.${fieldPath}},例如 fieldPath 将包含来自嵌套对象模型的所需对象路径。
${model.${fieldPath}}
我可以通过使用获取实际的字段路径,但我不确定如何评估字符串并从中获取值
对此的任何帮助将不胜感激。
我不确定我是否理解正确,但我认为你只需要这个表达式:
${model[fieldPath]}
在 EL 中,点运算符和[]订阅基本相同:语法不同,但访问方式相同。
[]
<c:set var="fieldPath" value="${fieldPath}" /> ${model.get(fieldPath)}