用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要传到这个方法中配置文件和程序要怎么写

解决方案 »

  1.   

    HttpServletRequest这个类在服务器端才有
      

  2.   

    你可以像下面这样试下:
    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"/>
      

  3.   

    public HttpServletRequest getRequest(){
    return ServletActionContext.getRequest();
    }