双重嵌套 EL 变量?
我使用 Spring MVC 作为我的控制器,JSP 是我的表示层。
在我的 Spring 控制器中,我有:
model.put("issues", dataManager.getIssues());
model.put("functions", dataManager.getFunctions());
所以现在在我的 JSP 中,我可以访问
${requestScope['issues']}
${requestScope['functions']}
这一切都很好。但为了使我的代码可扩展,我想将变量名 issues
和 functions
存储在数据库内,然后可以通过 issues
上的属性来访问它们。 code>configs 正在循环的对象。所以我想要的结果如下:
<c:forEach items="${configs}" var="cfg">
<c:if test="${cfg.configType == 'select'}">
<th>${cfg.header}</th>
<td><myTagLib:select values="${requestScope['${cfg.selectorName}']}" /></td>
</c:if>
</c:forEach>
其中 ${cfg.selectorName}
将保存 issues
或 functions
在这个例子中。
I'm using Spring MVC for my controller, and JSPs are my presentation layer.
Inside my Spring controller, I have:
model.put("issues", dataManager.getIssues());
model.put("functions", dataManager.getFunctions());
So now inside my JSP, I have access to
${requestScope['issues']}
${requestScope['functions']}
That's all well and good. But in order for my code to be extensible, I would like to store the variable name issues
and functions
inside the database, which will then be accessible through a property on a configs
object that's being looped over. So what I'd like to end up with is something like the following:
<c:forEach items="${configs}" var="cfg">
<c:if test="${cfg.configType == 'select'}">
<th>${cfg.header}</th>
<td><myTagLib:select values="${requestScope['${cfg.selectorName}']}" /></td>
</c:if>
</c:forEach>
Where ${cfg.selectorName}
will hold either issues
or functions
in this example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你很接近了。您只需删除嵌套的
${}
因为这是无效的语法。You're close. You only need to remove the nested
${}
since that's invalid syntax.