org.cnbi.web.interceptors.LicenseInterceptor.java Source code

Java tutorial

Introduction

Here is the source code for org.cnbi.web.interceptors.LicenseInterceptor.java

Source

package org.cnbi.web.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.cnbi.utils.pojo.MsgBean;
import org.cnbi.utils.tools.Constants;
import org.cnbi.web.utils.ContextHolderUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

/**
 * Copyright  2014?. All rights reserved.
 * 
 * @Author 
 * @Time 201441?5:10:22 license
 */
public class LicenseInterceptor extends HandlerInterceptorAdapter {

    /**
     * controller?
     */
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object object,
            Exception exception) throws Exception {

    }

    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object,
            ModelAndView modelAndView) throws Exception {

    }

    /**
     * controller?
     */
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object object)
            throws Exception {
        MsgBean errorMsg = (MsgBean) ContextHolderUtils.getServletContext()
                .getAttribute(Constants.LICENSE_CHECK_INFO);
        boolean flag = false;
        if (errorMsg.getFlag() == false) {
            flag = true;
        } else {
            request.setAttribute("errorMsg", errorMsg.getText());
            request.getRequestDispatcher("/noLicense.jsp").forward(request, response);
        }
        return flag;
    }

}