struts全局结果集,动态结果集

本文详细介绍了Struts2框架中全局结果集和动态结果集的配置与应用,通过示例代码展示了如何在action中设置结果集,并在配置文件中引用这些结果集来实现页面跳转。

全局结果集
        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>

此包中所有action都共享这个结果集

若其此其它配置文件也想共享此结果集,可在package配置属性extends="包名"

 

动态结果集

 在action中设置字符串属性resul,在配置文件reuslt结果页面用¥{result}访问值栈元素

 

package action;

import java.util.Map;

import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport{
 
 
    private int type;
    private String result;
   
 public int getType() {
  return type;
 }
 public void setType(int type) {
  this.type = type;
 }
 public String getResult() {
  return result;
 }
 public void setResult(String result) {
  this.result = result;
 }
  
    public String execute(){
     
     if(type==1)
      result="/hello.jsp";
     else
      result="/index.jsp";
     return "success";
    }

}

<action name="user" class="action.UserAction" >
    <result>${result}</result>
    </action>

转载于:https://www.cnblogs.com/xiaoguizi/p/struts2_resultset.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值