webwork中,action 中变量的取得
Posted on 2005-08-16 18:56 胡冰 阅读(233) 评论(0) 编辑 收藏 网摘 所属分类: webwork <!-- <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> <rdf:Description rdf:about="http://www.cnblogs.com/suibing/articles/216262.html" dc:identifier="http://www.cnblogs.com/suibing/articles/216262.html" dc:title="" trackback:ping="http://www.cnblogs.com/suibing/services/trackbacks/216262.aspx" /> </rdf:RDF> -->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()