Struts2中标签中的type是怎么来的呢?我们可不可以自己设定一个结果集呢?
-
基本操作步骤:
(1).自己写一个类
(2).在struts2配置文件中声明该结果集
(3).使用
(4).在自定义结果集中传递参数 -
自己写的那个类
(1).如果有刷新操作(转发,重定向),继承抽象类StrutsResultSupport
(2).如果无刷新操作,只需要实现接口Result即可 -
在struts2配置文件中声明该结果集
<package name="ajax" namespace="/" extends="struts-default"> <result-types> <result-type name="ajax" class=“pgg.AjaxResult”> </result-type> <result-type name="disp" class=“pgg.DispatcherResult”> </result-type> <result-types> </package>
-
使用
<result type="ajax"></result>
注:type中属性的内容和result-type中name的内容一致
-
在自定义结果集中传递参数
5.1.传递简单参数
^1.在结果集中定义几个属性,并且要有set方法
^2.在配置文件中通过以下方式传递过去5.2传递引用类型参数
^1.在action中将要传递的参数放到map栈中
^2.在结果集中利用valueStack.findValue()方法获取
5.1
<result type="disp">
<param name="location">index.jsp</param>
<param name="aa">aa</param>
</param>