[阅读: 739] 2005-11-29 03:45:10
package com.service.customerlogin;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class customerLoginAction extends Action {
public ActionForward execute(ActionMapping actionMapping,
ActionForm actionForm, HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
customerLoginForm customerloginForm = (customerLoginForm) actionForm;
customerDTO customerInfo = null;
customerDAO customerDao = null;
ActionForward forward = null;
ActionErrors errors = new ActionErrors();
HttpSession session = httpServletRequest.getSession();
try {
customerDao = customerDAOFactory.getDAO();
customerInfo = customerDao.getCustomer(customerloginForm.getLoginName());
if (customerInfo == null) {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"error.user.notfound"));
forward = actionMapping.getInputForward();
} else {
if (customerloginForm.getPassWord().trim().equals(
customerInfo.getPassWord())) {
session.setAttribute("customer", customerInfo);
forward = actionMapping.findForward("success");
} else {
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
"error.password.mismatch"));
forward = actionMapping.getInputForward();
}
}
} catch (Exception e) {
e.printStackTrace();
}
if (!errors.isEmpty()) {
saveErrors(httpServletRequest, errors);
}
return forward;
}
}