读书人

struts2 interceptor 获取访问种及方法

发布时间: 2012-06-30 17:20:12 作者: rapoo

struts2 interceptor 获取访问类及方法进行拦截

public class LoginInterceptor extends AbstractInterceptor {

?? @Override
?? public String intercept(ActionInvocation invocation) throws Exception {
?????? ? ActionProxy proxy = invocation.getProxy();
???????? String methodName = proxy.getMethod();
???????? String actionName = proxy.getActionName();
???????? if ("login".equals(actionName)) {
????????????? ?return invocation.invoke();
???????? }
???????? if (!(isLogin())) {
??????????? ActionContext actionContext = invocation.getInvocationContext();
??????????? HttpServletRequest request = (HttpServletRequest) actionContext
?????????????????????????????? .get(StrutsStatics.HTTP_REQUEST);
??????????? HttpServletResponse response = (HttpServletResponse) actionContext
?????????????????????????????? .get(StrutsStatics.HTTP_RESPONSE);
?????????? response.sendRedirect(request.getContextPath()
??????????????????????? + "/loginmgmt/login!login.action");?
???????????return null;
???????? }
??????? return invocation.invoke();
??? }

}

?

读书人网 >开源软件

热点推荐