日期:2014-05-18  浏览次数:20686 次

spring AOP 高手请入(struts+spring遇到的问题)
在实际项目中遇到一个需要AOP解决的问题,就是执行struts的dispatchAction中的一个方法时,先要使用AOP判断一下,当前用户能不能调用该方法。以下是代码:
public   Object   invoke(MethodInvocation   invocation)   throws   Throwable
{
  HttpServletRequest   request   =   (HttpServletRequest)invocation.getArguments()[2];  

  String   method=request.getParameter( "action ");  

  if   ( "getAllDeptMent ".equals(method))
{
Selecteduser   user=deptManagerService.getSelectedUserList();
                  if(user.getName!= "systemAdmin ")
                  {
                        return   new   Integer(1);
                    }

}

Object   result   =   invocation.proceed();  

return   result;
}
现在要做一个操作,如果user.getName!= "systemAdmin "希望直接返回到一个错误提示页面,这该怎么做啊?

------解决方案--------------------
根据我原来在csdn查询的结果
spring的aop不能拦截到DispathAction的方法
只能拦截到Action的execute方法

转发可用如下的代码——
request.getRequestDispatcher( "/WEB-INF/error.jsp ").forward(request,response);