spring aop怎么取到struts 2的HttpRequest,Session等值
展开全部
package com.util;
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
public class ThreadTest implements Serializable{
private static ThreadLocal<Object> threadLocal = new ThreadLocal<Object>();
public HttpServletRequest getContext(){
return (HttpServletRequest)threadLocal.get();
}
public void setContext(HttpServletRequest request){
threadLocal.set(request);
}
public void cleanContext(){
threadLocal.set(null);
}
}
配置为filter
<filter>
<filter-name>test</filter-name>
<filter-class>com.util.ThreadTest</filter-class>
</filter>
<filter-mapping>
<filter-name>test</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
import java.io.Serializable;
import javax.servlet.http.HttpServletRequest;
public class ThreadTest implements Serializable{
private static ThreadLocal<Object> threadLocal = new ThreadLocal<Object>();
public HttpServletRequest getContext(){
return (HttpServletRequest)threadLocal.get();
}
public void setContext(HttpServletRequest request){
threadLocal.set(request);
}
public void cleanContext(){
threadLocal.set(null);
}
}
配置为filter
<filter>
<filter-name>test</filter-name>
<filter-class>com.util.ThreadTest</filter-class>
</filter>
<filter-mapping>
<filter-name>test</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询