[英]How do I display different content with a jsp:include and jsp:param
[英]How do I display action data in a JSP?
我在JSP中使用<s:iterator>
标记来显示人员对象List
。
我尝试在动作类ListOfPersons
与List
一起创建, ListOfPersons
其与getter和setter一起创建。 我仍然无法显示数据-如何处理?
<s:iterator value="ListOfpersons" status="stat">
当我尝试打印列表的大小时,我得到的是零。
如果我理解正确,那么在JSP页面上使用OGNL表示列表时会遇到问题。 您应该使用YourListName[index].property
格式命名字段。 然后,OGNL将了解您有一个名为YourListName
的列表,并且其index
元素具有在其输入中带有值的property
。
请参见下面的示例:
<table>
<s:iterator value="ListOfpersons" status="status">
<tr>
<td><s:textfield name="ListOfpersons[%{#status.index}].firstname"/></td>
<td><s:textfield name="ListOfpersons[%{#status.index}].lastname"/></td>
<td><s:textfield name="ListOfpersons[%{#status.index}].age"/></td>
<td><s:textfield name="ListOfpersons[%{#status.index}].sex"/></td>
</tr>
</s:iterator>
</table>
简短答案:将信息存储在请求中,然后在jsp中访问它。
更长的答案:
一些代码(struts 1.x):
class Blah extends Action
{
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
{
... do stuff
request.setAttribute("Blammy", "Blammy Value");
... return some ActionForward.
}
}
在JSP中:
<span>The value of the Blammy variable is this here thing: ${Blammy}</span>
要么
<span>The value of the Blammy variable is this here thing: <c:out value="${Blammy}"/></span>
一旦掌握了基本概念,就可以为有问题的List
设置一个request属性,并使用JSP中的iterator标记对其进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.