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 LoginAction extends Action {

    public ActionForward perform(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response)
    {
        String username = ((LoginForm) form).getUserName();
        String password = ((LoginForm) form).getPassword();
        ActionErrors errors = new ActionErrors();
        if ((!username.equals("deryl")) || (!password.equals("radar")))
            errors.add("password",new ActionError("error.password.mismatch"));
        if ( errors.size()>0 ) {
            saveErrors(request,errors);
            return mapping.findForward("login");
        }
        // 存储权限到attribute中
        HttpSession session = request.getSession();
        session.setAttribute("authentication", username);
        // 控制转移到页面
        return mapping.findForward("success");
    }
}
