struts2的拦截器AbstractInterceptor「建议收藏」

2022-08-27 15:32:59 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

public class AuthorizationInterceptor extends AbstractInterceptor {

@Override public String intercept(ActionInvocation ai) throws Exception { Map<?, ?> session = ai.getInvocationContext().getSession(); UsrinfVO actor = (UsrinfVO) session.get(Constants.LGNUSR); if (actor == null) { actor = SpringUtil.getLgnUsr(); } Action action = (Action) ai.getAction(); if (action instanceof UsrAction) { return ai.invoke(); } HttpServletRequest request = ServletActionContext.getRequest(); // AJAX request session time out handle String type = request.getHeader(“X-Requested-With”); if ( type != null && type.equalsIgnoreCase(“XMLHttpRequest”)) { if(!validateLoginStatus(actor)){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType(“text/html;charset=utf-8”); PrintWriter pw = response.getWriter(); //request.setAttribute(“message”, “timeout”); Log.info(“Ajax 超时”); pw.write(“timeout”); return null; } } if (!validateLoginStatus(actor)) { Log.info(“超时退出”); return “goLoginAppPage”; } return ai.invoke(); } }

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/146374.html原文链接:https://javaforall.cn

0 人点赞