BaseAction


public class BaseAction extends ActionSupport {
	protected PageBean pageBean = new PageBean();
	
	//获取分页实体类
	public PageBean getPageBean(){
		return this.pageBean;
	}
	public void setPageBean(PageBean pageBean){
		this.pageBean = pageBean;
	}
	//获取请求对象
	public HttpServletRequest getHttpServletRequest(){
		return (HttpServletRequest)ActionContext.getContext().get("com.opensymphony.xwork2.dispather.HttpServletRequest");
	}
	//获取响应对象
	public HttpServletResponse getHttpServletResponse(){
		return (HttpServletResponse)ActionContext.getContext().get("com.opensymphony.xwork2.dispather.HttpServletResponse");
	}
	//获取session
	public Map getSession(){
		return ActionContext.getContext().getSession();
	}
	//jsp内置对象获取session
	public HttpSession getHttpSession(){
		return ServletActionContext.getRequest().getSession();
	}
	//获取会话保存的信息
	public Admin getServerSession(){
		return (Admin)getHttpSession().getAttribute("admin");
	}
}

Struts2 中action获取session也有另一种方法:

Action实现org.apache.struts2.interceptor.SessionAware(获取request用org.apache.struts2.interceptor.RequestAware)接口的方式来对session进行操作,加入如下代码:

Map<String,Object> session;

@Override

public void setSession(Map<String,Object> session){

this.session=session;

}

获取request则如下:

Map<String,Object> request;

@Override

public void setRequest(Map<String,Object> request){

this.request=request;

}

将以上内容放到BaseAction里作用一样,



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值