Struts2 - View页面中获取Action的成员变量
Struts2 - View页面中获取Action的成员变量
View页面中获取Action的成员变量
按照Struts的设计,在Action处理完后,把结果数据保存在自己的成员变量里,然后跳至result指定的页面(VIEW页面)。
VIEW页面负责展现处理结果,那VIEW中如何获取Action的数据呢?
方法一:Struts2 Property Tag / OGNL
http://struts.apache.org/2.x/docs/using-struts-2-tags.html
http://www.vaannila.com/struts-2/struts-2-example/struts-2-ognl-expression-language-example-1.html
比如,在Action里有一个成员变量helloCount及其对应的getter
private int helloCount = 0;
public int getHelloCount() {
return helloCount;
}
public void setHelloCount(int helloCount) {
HelloWorldAction.helloCount = helloCount;
}
则在VIEW.jsp中,
宣布使用struts的tag
<%@ taglib prefix="s" uri="/struts-tags" %>
可以使用下面的tag来显示helloCount的值:
I've said hello <s:property value="helloCount" />
方法二: HttpRequest的getAttribute方法
实际上, 在Action处理完之后,跳到result页面之前,struts应用把Action对象的成员变量放到了request的属性里(机制未知)
所以,可以用request对象来获取Action的成员变量。
【似乎只能获取Object,不能获取int这种变量】
<%
String username = (String) request.getAttribute("username");
%>、
struts2文件上传(保存为BLOB格式)
Struts2的入门实例
Struts2实现ModelDriven接口
遇到的Struts2文件下载乱码问题
Struts2整合Spring方法及原理
Struts2 注解模式的几个知识点
Struts 的详细介绍:请点这里
Struts 的下载地址:请点这里
本文永久更新链接地址:
评论暂时关闭