protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession(true);
        
        //add request bean
        beans.RLogin rLogin = new beans.RLogin();
        request.setAttribute("rLogin", rLogin);
        
        //if the user is not logged in
        if (request.getUserPrincipal() == null){
            //if login error
            //fill RLogin bean to pass back the error message
            if (request.getServletPath().contains(URLConfig.SURL_loginError)){
                rLogin.setErrorMessage("Username or password is incorrect");
                request.setAttribute("rLogin", rLogin);
                //dispatch to log in page
                this.getServletContext().getRequestDispatcher(URLConfig.JURL_login).forward(request, response);
            }
            // /login is called by java container before any servlet
            else{
                if (session.getAttribute(common.BeansConfig.sStatus) == null){
                    beans.SStatus sStatus = new beans.SStatus();
                    session.setAttribute(BeansConfig.sStatus, sStatus);
                }
                
                //set language
                if (request.getParameter("lang") != null
                    && beans.languageBeans.LanguageBeanPicker.isLanguageCodeExit(request.getParameter("lang"))){
                    beans.SStatus sessionStatus = (beans.SStatus)session.getAttribute(common.BeansConfig.sStatus);

                    //put the languag option into the bean
                    //create language bean
                    if (!request.getParameter("lang").equalsIgnoreCase(sessionStatus.getLanguageOption())
                            || session.getAttribute(common.BeansConfig.sLanguageBean) == null){
                        sessionStatus.setLanguageOption(request.getParameter("lang"));
                        beans.accessInterface.LanguageBean sLanguageBean = beans.languageBeans.LanguageBeanPicker.getLanguageBean(sessionStatus.getLanguageOption());
                        session.setAttribute(common.BeansConfig.sLanguageBean, sLanguageBean);
                    }
                }
                else if (session.getAttribute(common.BeansConfig.sLanguageBean) == null){
                    beans.SStatus sessionStatus = (beans.SStatus)session.getAttribute(common.BeansConfig.sStatus);
                    beans.accessInterface.LanguageBean sLanguageBean = beans.languageBeans.LanguageBeanPicker.getLanguageBean(sessionStatus.getLanguageOption());
                    session.setAttribute(common.BeansConfig.sLanguageBean, sLanguageBean);
                }
            }
            //dispatch to log in page
            this.getServletContext().getRequestDispatcher(URLConfig.JURL_login).forward(request, response);
            
        }
        else{
            //if /logout
            //invalidate the session and clean up the session information
           if (request.getServletPath().contains(URLConfig.SURL_logout)){
                session.invalidate();
            }
            
            //redirect the user to index page after actively logging in
            response.sendRedirect(URLConfig.getFullPath(URLConfig.SURL_index));
            
        }
    }