您的位置:首页 > 理论基础 > 计算机网络

Struts2 HTTP对象传递

2016-05-09 17:44 459 查看
本文为博主原创,允许转载,但请声明原文地址:http://www.coselding.cn/blog/8/8-147.html

1、 HTTP对象传递:

(1)ActionContext对象获取常用HTTP对象:

ActionContext ac = ActionContext.getContext(); //上下文对象相当于request范围

HttpServletRequest request =(HttpServletRequest)ac.get(StrutsStatics.HTTP_REQUEST);

HttpSession session = request.getSession(false);

ServletContext application = session.getServletContext();

ServletContext application = ac.get(StrutsStatics.SERVLET_CONTEXT);

HttpServletRequest request = ServletActionContext.getRequest(); (推荐使用)

HttpServletResponse response =ServletActionContext.getResponse();

(2)获取Map集合:

ActionContext ac = ActionContext.getContext();

Mapsession = ac.getSession();

Mapsession2 =(Map)ac.get("session");

Mapsession3=(Map)ac.get(ActionContext.SESSION);

(3)获取值栈对象和参数集合对象:

ActionContext ac = ActionContext.getContext();

ValueStack vs = ac.getValueStack();

Map paramts = ac.getParameters();

2、 实现接口获取HTTP对象:

ServletContextAware 实现此接口后,可以取得ServletContext

ServletRequestAware 实现此接口后,可以取得HttpServletRequest

ServletResponseAware 实现此接口后,可以取得HttpServletResponse

SessionAware 实现此接口后,可以取得HttpSession,注意,这里有点特殊,取得的是一个Map<String,Object> session,拦截器负责将session中存储的键值进行解析,并一一对应.

本文为博主原创,允许转载,但请声明原文地址:http://www.coselding.cn/blog/8/8-147.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: