loginaction.java

来自「公司自己开发的工作流引擎」· Java 代码 · 共 70 行

JAVA
70
字号
package cn.com.iaspec.workflow.client.web.action.privilege;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import cn.com.iaspec.workflow.client.*;
import cn.com.iaspec.workflow.client.web.action.base.*;
import cn.com.iaspec.workflow.exception.*;
import cn.com.iaspec.workflow.util.*;
import cn.com.iaspec.workflow.vo.workflow.*;

/**
 * 登录action
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2005</p>
 * <p>Company: IASPEC Technologies</p>
 * @author xiesonglin
 * @version 1.0
 */
public class LoginAction
    extends BaseAction{
  public LoginAction(){
  }

  public ActionForward login(ActionMapping mapping,ActionForm form,
      HttpServletRequest request,HttpServletResponse response)
      throws Exception{
    String loginName=request.getParameter("loginName");
    String password=request.getParameter("password");
    try{
      WorkflowPrivilegeClient client=new WorkflowPrivilegeClient();
      UserInfo userInfo=client.login(loginName,password);
      if(userInfo==null)
          throw new Exception("用户名或密码不正确");
      //放在会话中
      HttpSession session=request.getSession(false);
      userInfo.setSessionId(session.getId());
      session.setAttribute(FlowWebKeys.USER_SESSION,userInfo);
      return mapping.findForward("main");
    }
    //用户名不正确

    catch(IncorrectLoginIdException ex){
      logger.error(ex);
      ex.printStackTrace();
      request.setAttribute("errorType","login_name_error");
      request.setAttribute("errorMessage",ex.getMessage());
      return mapping.findForward("index");
    }
    //密码不正确
    catch(IncorrectPasswordException ex){
      logger.error(ex);
      ex.printStackTrace();
      request.setAttribute("errorType","password_error");
      request.setAttribute("errorMessage",ex.getMessage());
      return mapping.findForward("index");
    }

    catch(Exception e)
    {
        logger.error(e);
      e.printStackTrace();
      request.setAttribute("errorType","password_error");
      request.setAttribute("errorMessage",e.getMessage());
      return mapping.findForward("index");

    }
  }
}

⌨️ 快捷键说明

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