用aop做个登录验证的程序
spring配置:
<bean id="securityHandler" class="com.lsy.security.SecurityHandler"/>
<aop:config>
<aop:aspect id="security" ref="securityHandler">
<aop:pointcut id="allAddMethod" expression="execution(* com.lsy.struts.action.*.execute(..))"/>
<aop:before method="checkSecurity" pointcut-ref="allAddMethod"/>
</aop:aspect>
</aop:config>
SecurityHandler.java:
public class SecurityHandler {
private void checkSecurity(){
。request要传到这个方法中配置文件和程序要怎么写
spring配置:
<bean id="securityHandler" class="com.lsy.security.SecurityHandler"/>
<aop:config>
<aop:aspect id="security" ref="securityHandler">
<aop:pointcut id="allAddMethod" expression="execution(* com.lsy.struts.action.*.execute(..))"/>
<aop:before method="checkSecurity" pointcut-ref="allAddMethod"/>
</aop:aspect>
</aop:config>
SecurityHandler.java:
public class SecurityHandler {
private void checkSecurity(){
。request要传到这个方法中配置文件和程序要怎么写
解决方案 »
- JSP bug求解
- 下载文件时,选择直接打开,如何保证文件名不被修改
- Eclipse下怎么配置Tomcat自动编译JAVA类文件
- 高手帮忙!
- 我想在,插入或更新之后,弹出一个对话框,显示插入或者更新成功该怎么做呢? 急......跪求解决方法~
- 初学者的疑惑,请兄弟姐妹们帮忙看看,谢谢了先!
- 程序发了那么多,有一个大bug竟然都没人提过!!
- session的读写的问题
- 问一次servlet编译的问题 ,请各位大侠帮忙吧!
- JPA Attempting to execute an operation on a closed EntityManager
- 圖片上傳,預覽問題
- MyEclipse8.5中使用Struts2的问题
1.切面:@Aspect
public class ActionBeforeAspect {
private Logger logger = Logger.getLogger(this.getClass().getName());
@Pointcut("within(com.makeprogress.struts.action.*)")//拦截所有action的execute方法
public void service(){}
@Before("service() && args(map,fo,req,res)")//
public void beforeAspect(JoinPoint jp,ActionMapping map,ActionForm fo,HttpServletRequest req,HttpServletResponse res){
//通过JoinPoint获得目标类名
logger.log(Level.INFO, "Action:"+jp.getTarget().getClass().getName());
//通过request对象获得用户在页面输入的用户名
String re = (String)req.getParameter("username");
logger.log(Level.INFO, "username: "+re);
}
}2.在applicationContext.xml中只需做如下配置
//将切面类配置在xml文件中
<bean id="actionBeforeAspect" class="com.makeprogress.aspectj.ActionBeforeAspect"/>
return ServletActionContext.getRequest();
}