FileDocCategorySizeDatePackage
LoginAction.javaAPI DocExample1513Sat Nov 22 19:35:12 GMT 2003s2wexample.controller.actions

LoginAction

public class LoginAction extends Object implements Action
An action to log a user in

Fields Summary
public static final String
USERBEAN_ATTR
The name of the UserBean in the session
private static final String
NAME_PARAM
parameters shared with the JSP page
private static final String
PASSWORD_PARAM
Constructors Summary
Methods Summary
public booleanperformAction(javax.servlet.http.HttpServletRequest req, javax.servlet.ServletContext context)
Perform this action. Try to log the user in based on the username and password in the submitted request

    
                             
        
                                  
    
        // read the username and password from the request
        String username = req.getParameter(NAME_PARAM);
        String password = req.getParameter(PASSWORD_PARAM);
        
        // get the UserBean from the session
        HttpSession session = req.getSession();
        UserBean ub = (UserBean) session.getAttribute(USERBEAN_ATTR);
        
        // if the UserBean doesn't exist, create it
        if (ub == null) {
            ub = UserBeanFactory.newInstance();
            session.setAttribute(USERBEAN_ATTR, ub); 
        }
        
        // set the parameters in the bean
        ub.setUsername(username);
        ub.setPassword(password);
        
        // try to login
        return ub.doLogin();