webwork中,action 中变量的取得

 

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值