2012-04-24 14:34 struts2监听器首先要实现com.opensymphony.xwork2.interceptor.PreResultListener类
来源:互联网 发布:手机数据是什么 编辑:程序博客网 时间:2024/04/30 12:52
struts2监听器
首先要实现com.opensymphony.xwork2.interceptor.PreResultListener类
并重写里面的方法beforeResult
- public class MyListener implements PreResultListener {
- public void beforeResult(ActionInvocation invocation, String resultCode) {
- System.out.println(resultCode);
- }
- }
然后再在拦截器里面调用
- invocation.addPreResultListener(new MyListener());
监听器是在这个拦截器完成别的拦截器之后调用的
struts2 Action获得HttpSession,HttpServletRequest,HttpSevletResponse的方法
非IOC方式
这种方式主要是利用了com.opensymphony.xwork2.ActionContext类以及org.apache.struts2.ServletActionContext类
- ActionContext ctx = ActionContext.getContext();
- HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
- HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);
- //ServletActionContext.APPLICATION;
- //ServletActionContext.SESSION;
- //ServletActionContext.PAGE_CONTEXT;
- //或者
- HttpServletRequest request = ServletActionContext.getRequest ();
主要是这两个类com.opensymphony.xwork2.ActionContext和org.apache.struts2.ServletActionContext都对request等进行了大量的封装,直接调用方法就可以获和
更好一点的IOC方式
action类实现ServletRequestAware接口,并新建一个HttpServletRequest request
- public class UserLoginAction extends ActionSupport implements ServletRequestAware{
- public void setServletRequest(HttpServletRequest request) {
- this.request=request;
- }
- 然后可以生成的request得到对象,如request.getRemoteAddr()
- action类实现SessionAware接口,并创建一个MAP对象session
- public class UserLoginAction extends ActionSupport implements ServletRequestAware,SessionAware{
- public void setServletRequest(HttpServletRequest request) {
- this.request=request;
- }
- public void setSession(Map session) {
- this.session=session;
}
这些获得HttpServletRequest等对象需要implments的接口都在
org.apache.struts2.interceptor下面
如Apllication的是ApplicationAware
如HttpSession的是SessionAware(struts2的Session都被封装成Map了)
如HttpServletRequest的是ServletRequestAware
如HttpServletResponse的是ServletResponseAware
- 2012-04-24 14:34 struts2监听器首先要实现com.opensymphony.xwork2.interceptor.PreResultListener类
- com.opensymphony.xwork2.interceptor.ParametersInterceptor
- com.opensymphony.xwork2.interceptor.ParametersInterceptor error(未完成)
- struts2 出现com.opensymphony.xwork2.util.ValueStack
- Source Taste: Struts 2: com.opensymphony.xwork2.interceptor.ParametersInterceptor
- com.opensymphony.xwork2.ActionSupport类源码
- 类com.opensymphony.xwork2.config.providers.XmlConfigurationProvider
- [Struts2]Caused by: com.opensymphony.xwork2.inject.DependencyException:
- Struts2 Problem-java.lang.NoSuchMethodException: com.opensymphony.xwork2.ActionSupport.index()
- struts2,struts-2.3.15.2,关注:com.opensymphony.xwork2.DefaultActionInvocation.invokeAction()
- 关于:[Struts2]Caused by: com.opensymphony.xwork2.inject.DependencyException:
- struts2 com.opensymphony.xwork2.config.ConfigurationException: 异常原因
- Struts2拦截器(Interceptor) PreResultListener
- com.opensymphony.xwork2.inject.DependencyException
- Unable to load bean: type:com.opensymphony.xwork2.ObjectFactory class:org.apache.struts2.spring.StrutsSpringObjectFactory - bean
- struts2出现at com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java:20
- struts2-java.lang.NullPointerException at com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.j
- struts2-java.lang.NullPointerException at com.opensymphony.xwork2.util.FileManager$FileRevision.needsReloading(FileManager.java
- windows进程能打开的最大句柄数目
- SVN与Git比较
- android 中英混合字符串数组按首字母进行排序
- Android开发_如何设置按钮背景透明与半透明_图片背景透明
- postgresql 加解密
- 2012-04-24 14:34 struts2监听器首先要实现com.opensymphony.xwork2.interceptor.PreResultListener类
- ognl.ExpressionSyntaxException: Malformed OGNL expression: nbsp;的解决
- Android设置文字粗体的方法
- IntelliJ IDEA的Singleton模版的修改
- windows8中的ListView控件的属性
- weblogic启动报错,登录失败。
- 去掉 IBM Portal7 主题里多余的功能
- 黑马程序员_java入门_数组
- 解决XP 系统 .Net Framework 4安装时出现严重错误 (0x80070643)