在jsp中使用java对象
<c:set var="nameLookup" value="${names}" />
<c:forEach var="result" items="${results}">
<tr>
<td>${result.uglyDisplayName}</td>
<td>${result.phonenum}</td>
</tr>
</c:forEach>
这是我正在尝试编辑的 jsp 的摘录。
结果是从控制器在 ModelAndView 中返回的 List
在控制器中,我添加了另一个要在 ModelAndView 中返回的对象。 它是一个具有更好显示名称的 HashMap,而丑陋的显示名称是其键。 所以我想用这样的东西替换第一个 td:
<td>${nameLookup.get(result.uglyDisplayName)}</td>
显然,这不起作用,否则我不会在这里发帖。 我继续将 var 设置为我将 HashMap 放在 ModelAndView 中(顶行)下的名称,但我不确定这是否是获取该对象的正确方法。
<c:set var="nameLookup" value="${names}" />
<c:forEach var="result" items="${results}">
<tr>
<td>${result.uglyDisplayName}</td>
<td>${result.phonenum}</td>
</tr>
</c:forEach>
This is an excerpt from a jsp I'm trying to edit.
Results is a List<Object>
being returned in the ModelAndView from the controller, of which each Object
has a getUglyDisplayName
and getPhonenum
. I'm not actually clear on how that's working. I guess the jsp is doing some getClass().getName()
or something behind the scenes? Any pointers on that process would be enlightening. Anyway, that part is working.
In the controller I've added another object to be returned in the ModelAndView. It's a HashMap that has nicer display names for which the ugly display names are the keys. So I want to replace that first td with something like this:
<td>${nameLookup.get(result.uglyDisplayName)}</td>
This doesn't work, obviously, or I wouldn't be posting here. I went ahead and set a var to the name I put the HashMap in the ModelAndView under (top line) but I'm not sure if that's the right way to get at that object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于第一部分(“JSP 正在做什么”),请参阅 JSP 表达式语言。
对于第二部分,请尝试:
我不想发誓它会起作用(自从我使用 JSP 以来已经很长时间了),但它值得一试。
For the first part ("what JSP is doing") see the JSP Expression Language.
For the second part, try:
I wouldn't like to swear it'll work (it's a long time since I've used JSP) but it's worth a try.