webwork中,action 中变量的取得

王朝java/jsp·作者佚名  2006-01-31
窄屏简体版  字體: |||超大  

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()

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航