标签:操作 except ssi writer 执行 getattr utf-8 接口 tps
<mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <mvc:exclude-mapping path="/user/login"/> <!-- 不拦截登录请求 --> <mvc:exclude-mapping path="/user/logout"/> <!-- 不拦截注销请求 --> <mvc:exclude-mapping path="*.jsp"/> <mvc:exclude-mapping path="*.html"/> <mvc:exclude-mapping path="*.js"/> <mvc:exclude-mapping path="*.css"/> <bean class="org.huaxin.interceptor.AccessInterceptor"></bean> </mvc:interceptor> </mvc:interceptors>
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object obj) throws Exception { System.out.println("[AccessInterceptor]:preHandle执行"); HttpSession session = request.getSession(); ServletContext application = session.getServletContext(); if(application.getAttribute(session.getId()) == null){ //未登录 PrintWriter out = response.getWriter(); StringBuffer sb = new StringBuffer("<script type=\"text/javascript\" charset=\"UTF-8\">"); sb.append("alert(\"你的账号被挤掉,或者没有登录,或者页面已经过期,请重新登录\")"); sb.append("window.location.href=‘/user/logout‘;"); sb.append("</script>"); out.print(sb.toString()); out.close(); return false; }else{ //已经登录 return true; } }
SpringMVC拦截器实现:当用户访问网站资源时,监听session是否过期
标签:操作 except ssi writer 执行 getattr utf-8 接口 tps
原文地址:http://www.cnblogs.com/javafucker/p/7726265.html