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
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
相关文章推荐
- Android OkHttp完全解析 是时候来了解OkHttp了
- 简析TCP的三次握手与四次分手
- delphi使用IdHTTP模拟提交页面方法总结
- NodeJS学习笔记之Http模块
- nodejs http 发送请求
- Nodejs获取网络数据并生成Excel表格
- 《网络游戏服务器编程》
- Delphi IDhttp 获取Cookie
- Linux服务器利用Nethogs监控每个进程的网络使用情况
- [置顶] KMeans算法检测网络异常入侵
- TCP/IP协议学习之TCP、IP篇
- delphi的idhttp的get 和 post的使用
- 网络编程知识(2)--Socket理解
- [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
- HTTP gzip和deflate的几点区别
- OkHttp+ Retrofit使用从0开始(一)
- 返回内部类网络判断的状态
- HTTP状态码:400\500 错误代码
- 【python学习】网络爬虫——基础案例教程
- Content-Type的几种常用数据编码格式