我們知道Struts2會將Action中的屬性存放到ValueStack對象中,在通過Action轉發的頁面中,我們可以通過Struts2的標簽<s:property/>來輸出這些值,但是這樣得到的值卻僅限于輸出顯示,不能進行進一步的操作,那么我們應該怎樣得到ValueStack中的值又能對它進行其他操作呢?
首先,我們需要了解Struts2是將Action中的屬性全部封裝在一個叫做struts.valueStack的請求屬性中,然后我們就可以通過下面的代碼來獲取這些值了:
<%@ page import="com.opensymphony.xwork2.util.*"%>
<%
ValueStack vs = (ValueStack)request.getAttribute("struts.valueStack");
List someThing= (List)vs.findValue("someThing");
%>
someThing是Action中屬性值的名稱。