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

全局结果集
        <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>

posted @ 2013-11-10 18:57  xiaoguizi  阅读(383)  评论(0)    收藏  举报