赞
踩
- public class CommInterceptor extends HandlerInterceptorAdapter{
- private final Logger log = LoggerFactory.getLogger(CommInterceptor.class);
- public String defultLogin="/account/login";//默认登录页面
- public Map<String,String> defineUrls;//自定义的Url,自定义拦截后的处理页面。
-
- @Override
- public boolean preHandle(HttpServletRequest request,
- HttpServletResponse response, Object handler) throws Exception {
-
- //从session获取登录信息
- if(SessionUtils.getAttribute(request, "user")!=null)
- {
- return true;
- }
- else
- {
- if(defineUrls!=null&&defineUrls.size()>0)
- {
- if(defineUrls.containsKey(url))
- {
- defultLogin=defineUrls.get(url).toString();
- }
- }
- log.info("Interceptor:跳转到login页面!"+defultLogin+"-----");
- response.sendRedirect(request.getContextPath()+defultLogin);
- return false;
- }
- }
-
- @Override
- public void postHandle(HttpServletRequest request,
- HttpServletResponse response, Object handler,
- ModelAndView modelAndView) throws Exception {
- }
-
- @Override
- public void afterCompletion(HttpServletRequest request,
- HttpServletResponse response, Object handler, Exception ex)
- throws Exception {
- }
-
- public String getDefultLogin() {
- return defultLogin;
- }
-
- public void setDefultLogin(String defultLogin) {
- this.defultLogin = defultLogin;
- }
-
- public Map<String, String> getDefineUrls() {
- return defineUrls;
- }
-
- public void setDefineUrls(Map<String, String> defineUrls) {
- this.defineUrls = defineUrls;
- }
- }
- <!--配置拦截器 -->
- <mvc:interceptors>
- <mvc:interceptor>
- <!--
- /**的意思是所有文件夹及里面的子文件夹
- /*是所有文件夹,不含子文件夹
- /是web项目的根目录
- -->
- <mvc:mapping path="/personCenter/*" />
- <mvc:mapping path="/web/exam/yuDingXinXi" />
- <mvc:mapping path="/web/preRegister/goYuYueDingDan" />
- <!-- 微信预约体检 -->
- <mvc:mapping path="/exam/yuDingXinXi" />
- <!-- 微信体质辨识 -->
- <mvc:mapping path="/healthJudge/healthJudge" />
- <bean class="com.xxx.webportal.chp.common.interceptor.CommInterceptor">
- <!--定义拦截后重定向到默认的登录处理页面 -->
- <property name="defultLogin" value="/account/login" />
- <!--定义拦截后重定向到其他登录处理页面 -->
- <property name="defineUrls">
- <map>
- <entry key="/exam/yuDingXinXi" value="/connect/wx/start" />
- <entry key="/healthJudge/healthJudge" value="/connect/wx/start" />
- </map>
- </property>
- </bean>
- </mvc:interceptor>
- </mvc:interceptors>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。