📄 loginaction.java
字号:
package edu.jnestore.action;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import edu.jnestore.beans.*;
import edu.jnestore.util.*;
import edu.jnestore.common.*;
import edu.jnestore.service.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import edu.jnestore.exceptions.*;
/**
* 处理登录请求
*/
public class LoginAction extends Action
{
public ActionForward execute(ActionMapping actionMapping ,
ActionForm actionForm ,
HttpServletRequest httpServletRequest ,
HttpServletResponse httpServletResponse)
{
Log bizlog=LogFactory.getLog("Businesslog");
Log errlog=LogFactory.getLog("Errlog");
HttpSession session = httpServletRequest.getSession();
IBizService bizservice = BizServiceFactory.createService();
Account account = null;
LoginActionForm loginForm =null;
try
{
loginForm = (LoginActionForm)actionForm;
account = bizservice.login(loginForm.getUserName(),loginForm.getPassword());
if(account != null )
{
session.setAttribute(Constants.USER_KEY,new User(account.getUserid()));
bizlog.info(account.getUserid() + " logon");
}
}
catch(DBException exception)
{
ActionErrors errors = new ActionErrors();
ActionError error = new ActionError("promt.dbexception");
errors.add( ActionErrors.GLOBAL_ERROR, error );
saveErrors( httpServletRequest, errors );
errlog.error("database operation failed");
return (actionMapping.findForward("failure"));
}
catch(LoginFailedException exception)
{
System.out.println("loginfail");
ActionErrors errors = new ActionErrors();
ActionError error = new ActionError("promt.loginfailedexception");
errors.add( ActionErrors.GLOBAL_ERROR, error );
saveErrors( httpServletRequest, errors );
bizlog.info("loginfailed with username "+ loginForm.getUserName());
return (actionMapping.findForward("failure"));
}
return actionMapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -