1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
// mon controle Action
public class ConnexionAction extends org.apache.struts.action.Action {
/* forward name="success" path="" */
private static final String SUCCESS = "success";
private final static String CANCEL = "cancel";
private final static String DISCONNECT = "disconnect";
SecurityManager thesecurity = new SecurityManager();
public ActionForward login (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ConnexionActionform testbeanform =(ConnexionActionform)form;
if (isCancelled(request)){
return mapping.findForward(CANCEL);
}
if(thesecurity.AuthenticateUser(testbeanform.getName(),testbeanform.getPassword()))
{
return mapping.findForward(SUCCESS);
}
else
{
ActionMessages errors = new ActionMessages();
ActionMessage error = new ActionMessage("errors.login.invalid");
errors.add("loginWrong",error);
saveErrors(request.getSession(),errors);
return mapping.getInputForward();
}
}
public ActionForward loginout (ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
if(thesecurity.Deconnexion())
{
return mapping.findForward(DISCONNECT);
}
else
{
return mapping.getInputForward();
}
}
}
// extrait de mon fichier de configuration struts.conf.xml
<action input="/accueil.jsp" name="ConnexionActionform" path="/loginout" scope="session" type="pl2.notes.struts.actions.ConnexionAction">
<forward name="discconnect" path="/connexion.jsp"/>
</action>
<action input="/connexion.jsp" name="ConnexionActionform" path="/login" scope="session" type="pl2.notes.struts.actions.ConnexionAction">
<forward name="success" path="/accueil.jsp"/>
</action> |
Partager