UserAction

来源:互联网 发布:高级网络管理 编辑:程序博客网 时间:2024/05/21 06:19

`package cn.bdqn.jboa.action;

import java.util.Map;
import cn.bdqn.jboa.entity.Employee;
import cn.bdqn.jboa.service.EmployeeService;
import cn.bdqn.jboa.utils.MD5;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
* 用户登录action。
*
* @author 北大青鸟
* @version 1.0
*/
public class UserAction extends ActionSupport {

private static final long serialVersionUID = -6095372451084071851L;private Employee employee = null;private EmployeeService employeeService = null;/** * 用户登录。 *  * @return * @throws Exception */public String login() throws Exception {    Employee newEmployee = null;    try {        // 对登录密码进行MD5加密        // employee.setPassword(new MD5(employee.getPassword()).compute());        newEmployee = employeeService.login(employee);    } catch (Exception e) {        this.addActionMessage(e.getMessage());    }    String ret = INPUT;    if (newEmployee == null) {        ret = INPUT;    } else {        Map<String, Object> session = ActionContext.getContext()                .getSession();        session.put("employee", newEmployee);        String nameCn = newEmployee.getPosition().getNameCn();        if ("普通员工".equals(nameCn)) {            ret = "staff";        } else if ("部门经理".equals(nameCn)) {            ret = "deptManager";        } else if ("总经理".equals(nameCn)) {            ret = "manager";        } else if ("财务".equals(nameCn)) {            ret = "cashier";        }    }    return ret;}/** * 用户退出。 *  * @return * @throws Exception */public String logout() throws Exception {    ActionContext ac = ActionContext.getContext();    ac.getSession().remove("employee");    return SUCCESS;}public void setEmployee(Employee employee) {    this.employee = employee;}public void setEmployeeService(EmployeeService employeeService) {    this.employeeService = employeeService;}public Employee getEmployee() {    return employee;}public EmployeeService getEmployeeService() {    return employeeService;}

}
这里写图片描述

0 0
原创粉丝点击