Jsp向Action中傳集合
阿新 • • 發佈:2019-01-29
在jsp頁面中遍歷的List集合在修改後若需傳回Action時可以通過如下程式碼實現:
<form action="detail!mai.action" method="post">
<s:iterator value="#request.showlist" status="st">
<input type="text" name="detaillist[<s:property value="#st.index"/>].com_id" value="<s:property value="com_id" />" />
<input type="text" name="detaillist[<s:property value="#st.index"/>].number" value="<s:property value="number" />" />
<input type="text" name="detaillist[<s:property value="#st.index"/>].price" value="<s:property value="price" />" />
<input type ="text" name="detaillist[<s:property value="#st.index"/>].photo" value="<s:property value="photo" />" />
<input type="text" name="detaillist[<s:property value="#st.index"/>].user_id" value="<s:property value="user_id" />" />
<br/>
</s:iterator>
<input type ="submit" value="確認訂單" align="right" />
</div>
</form>
其中:
showlist為後臺傳到jsp頁面中的集合;
detaillist為jsp將集合傳到Action後再Action中接收集合的list集合名。
通過該方法可輕鬆將一個list集合傳到Action中,且無需其他處理。