Struts2中使用Servlet API步骤
2015-12-10 23:53
483 查看
Struts2中使用Servlet API步骤
Action类中声明request等对象Map<String, Object> request;
获得ActionContext实例
ActionContext ac=ActionContext.getContext();
获取request等对象
request=(Map<String, Object>)ac.get("request");
在request等对象中保存数据
request.put("loginAccess", "登录地点是:北京");
request.get("loginAccess");
在页面中获取保存数据提倡的方式
<s:property value="#request.loginAccess"/>访问Servlet API
其它方式访问Servlet API
之前获得Servlet API对象的方式
自己获得request: ac.get("request")
Structs2=Structs1的知名度和市场+WebWork的技术 把字符串转成OGRL表达式%{}
自己获得session: ac.getSession()
让“别人”为你提供Servlet API的对象
通过实现相应接口获得Servlet API对象
获得request需要实现RequestAware接口
获得session需要实现SessionAware接口
获得application需要实现ApplicationAware接口
相关文章推荐
- java设计模式(五)—命令模式
- Ant之Task
- Java的一些小知识:package,import,不同目录下类的调用
- Java动态代理原理
- 三个例子讲清楚Java反射
- Java线程2-4 单任务线程池SingleThreadPool
- java并发--队列同步器原理一
- 第三个spring冲刺第4天
- java多线程模拟聊天问题
- JAVA面向对象
- Java线程2-3 时间调度的线程池ScheduledThreadPool
- Struts2框架学习之三:result返回结果
- Spring配置文件所有类型的数据源dataSource
- java web 答辩总结
- java.lang.IndexOutOfBoundsException 错误解决
- Java线程2-2 固定大小的线程池FixedThreadPool
- Java线程2-1 线程池知识学习
- java中的原子类
- java运算符
- struts常见面试题目