![](/img/trans.png)
[英]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.