Action文件:import com.opensymphony.xwork.ActionSupport;
public class HelloWebWorldAction extends ActionSupport {
String hello;
public String getHello() {
return hello;
}
public String execute() throws Exception {
hello = "Hello, WebWorld!";
return SUCCESS;
}
}
该action文件调用后转到下面的JSP
success.jsp:<%@ taglib uri="webwork" prefix="ww" %>
<html>
<head>
<title></title>
</head>
<body>
<ww:property value="hello" />
</body>
其实,success.jsp:中的
<ww:property value="hello" /> ,也可以用一下方式得到:
<%
OgnlValueStack stack = (OgnlValueStack)request.getAttribute("webwork.valueStack");
out.write("Hello, " +java.util.Arrays.toString((String[][])stack.findValue("countries")));
out.write("Hello, " +stack.findValue("name"));
%>
注意,这个VS是存到request scope中的变量,其KEY是"webwork.valueStack",其中存放了很多信息
一下是一些默认的信息:
WebWork2 contains the following items by default in the ValueStack:
req - the current HttpServletRequest res - the current HttpServletResponse stack - the current OgnlValueStack ognl - an instance of OgnlTool ui - a (now deprecated) instance of a ui tag renderer VS(valueStack),从上面的分析中可以得知,VS被放入了request 中,所以可以由一下方式得到
<ww:property value="#request['webwork.valueStack']" />
在JAVA程序中可以这么得到
ActionContext.getContext().getValueStack()