1 18 19 package org.apache.struts.faces.systest1; 20 21 import javax.servlet.http.HttpServletRequest ; 22 import javax.servlet.http.HttpServletResponse ; 23 24 import org.apache.commons.beanutils.PropertyUtils; 25 import org.apache.commons.logging.Log; 26 import org.apache.commons.logging.LogFactory; 27 28 import org.apache.struts.action.Action; 29 import org.apache.struts.action.ActionForm; 30 import org.apache.struts.action.ActionForward; 31 import org.apache.struts.action.ActionMapping; 32 import org.apache.struts.action.ActionError; 33 import org.apache.struts.action.ActionErrors; 34 35 36 42 43 public class LogonAction extends Action { 44 45 46 private static final Log log = LogFactory.getLog(LogonAction.class); 47 48 49 52 public ActionForward execute(ActionMapping mapping, 53 ActionForm form, 54 HttpServletRequest request, 55 HttpServletResponse response) 56 throws Exception { 57 58 ActionErrors errors = new ActionErrors(); 59 String username = (String ) 60 PropertyUtils.getSimpleProperty(form, "username"); 61 if ((username == null) || ("".equals(username))) { 62 errors.add("username", 63 new ActionError("logon.username")); 64 } 65 String password = (String ) 66 PropertyUtils.getSimpleProperty(form, "password"); 67 if ((password == null) || ("".equals(password))) { 68 errors.add("password", 69 new ActionError("logon.password")); 70 } 71 if (log.isTraceEnabled()) { 72 log.trace("username=" + username + ",password=" + password); 73 } 74 if (errors.isEmpty() && 75 (!"gooduser".equals(username) || !"goodpass".equals(password))) { 76 errors.add(ActionErrors.GLOBAL_ERROR, 77 new ActionError("logon.mismatch")); 78 } 79 if (errors.isEmpty()) { 80 if (log.isDebugEnabled()) { 81 log.debug("Successful logon, forwarding to logon1"); 82 } 83 return (mapping.findForward("logon1")); 84 } else { 85 if (log.isDebugEnabled()) { 86 log.debug("Unsuccessful logon, returning to input"); 87 } 88 saveErrors(request, errors); 89 return (mapping.getInputForward()); 90 } 91 92 93 94 } 95 96 97 } 98 | Popular Tags |