⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loginaction.java

📁 办公自动化项目
💻 JAVA
字号:
package com.t60.oa.login.struts;

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

import com.t60.oa.login.service.LoginService;
import hong.javanet.dao.HibernateAspect;
import org.apache.struts.action.*;
import org.apache.log4j.Logger;
import javax.servlet.http.HttpSession;
import org.apache.struts.validator.DynaValidatorForm;
import com.t60.oa.login.service.*;
/**
 *
 * <p>Title: </p>
 *
 * <p>Description: </p>
 * 检查用户是否合法,并存放用户名在session里面
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class LoginAction extends Action {
    private static Logger log=Logger.getLogger(LoginAction.class);
    /**
     * 1:验证用户合法性
     * 2:存入用户名到session
     * 3:存入这个用户的所有信息到session中(为了辨别不同用户不同权限)
     * @param mapping ActionMapping
     * @param form ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @return ActionForward
     */
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
        DynaValidatorForm loginActionForm = (DynaValidatorForm) form;
        String empName=loginActionForm.getString("empName");
        String pwd=loginActionForm.getString("pwd");

        LoginService ls=new LoginService();
        ls.setEmpName(empName);
        ls.setPwd(pwd);
    try {
        new HibernateAspect().bind(ls, "loginCheck").execute();
        if (ls.isFlag()) {

            request.getSession().setAttribute("userID",ls.getEmp().getId());//用户ID
            request.getSession().setAttribute("userName",ls.getEmp().getEmpName());//用户姓名

            request.getSession().setAttribute("emp",ls.getEmp());//用户对象
             request.getSession().setAttribute("purview",ls.getPurview());//用户权限集合
            request.getSession().setAttribute("depId",ls.getDepId());//用户部门Id集合
            request.getSession().setAttribute("dep",ls.getEmp().getDepEmpSet());//用户部门员工信息集合
            //request.getSession().setAttribute("purDoc",ls.getEmp().getFloadpurviewSet());//文档管理权限集合
            return mapping.findForward("succeed");
        }else{
            request.setAttribute("errors","用户名或密码出错!");
            return mapping.getInputForward();
        }
    } catch (Exception ex) {
        request.setAttribute("errors","用户名或密码出错!");
        return mapping.getInputForward();
    }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -