[ Struts ] erreur de redirection
Bonjour,
Voila g un pb avec un formulaire de login
Lorsque je le valide et que tout est ok, cad login et mdp correct, il me fait la bonne action (redirection vers une auter page)
Par contre lorsque je laisse les champs à blanc, g une erreur 404 du style
description
Code:
La ressource demandée (/loginIntervenant.jsp) n'est pas disponible.
Struts-config
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <!-- ========== Form Bean Definitions ================================== -->
<form-beans>
<form-bean name="loginIntervenantForm" type="x.x.view.struts.form.LoginIntervenantForm" />
<!-- ========== Action Mapping Definitions =============================== -->
<action-mappings>
<action
input="/loginIntervenant.jsp"
name="loginIntervenantForm"
path="/loginIntervenant"
scope="session"
type="x.x.view.struts.action.LoginIntervenantAction">
<forward name="success" path="planning.jsp" redirect="true" />
<forward name="failure" path="jsp/loginIntervenant.jsp"/>
</action> |
loginIntervenant.jsp
Code:
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
| <table bgcolor="#FFFFFF" align="center">
<tr>
<td valign="center" class="colonne">
<br><br><br>Veuillez-vous identifier
</td>
</tr>
<tr>
<td>
<br><br>
<font color="#FF0000" size="-1" face="arial"><strong>
<!-- permet d'afficher les erreurs -->
<html:errors />
</strong> </font>
<html:form action="loginIntervenant.do" name="loginIntervenantForm" type="com.capgemini.view.struts.form.LoginIntervenantForm" focus="login" scope="session">
<table align="center" width="112" cellpadding="0" cellspacing="0" border="0" style="vertical-align: middle">
<tr>
<td valign="top" class="normal" width="30" height="42">
<bean:message key="login.login"/>
</td>
<td valign="top" height="42">
<html:text property="login"/></br>
</td>
</tr>
<tr>
<td valign="top" class="normal" width="30" height="42">
<bean:message key="login.password"/>
</td>
<td valign="top" height="42">
<html:password property="password"/></br>
</td>
</tr>
</table>
<table align="center">
<tr align="CENTER" valign="top" height="15" width="100%">
<td valign="center">
<html:submit value="Valider"/>
</td>
</tr>
<tr align="right" valign="top" height="15" width="100%">
<td valign="center">
<br><a class="mdp" href="modifPassword.jsp">modifier mon mot de passe</a>
</td>
</tr>
</table>
</html:form>
</td>
</tr>
</table> |
Form
Code:
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
| /** password property */
private String password;
/** login property */
private String login;
// --------------------------------------------------------- Methods
/**
* Method validate
* @param ActionMapping mapping
* @param HttpServletRequest request
* @return ActionErrors
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
System.out.println("********************FORM LOGIN VALIDATE");
ActionErrors errors = new ActionErrors();
// Si Champ username vide -> erreur
if (this.login.length() == 0)
{ errors.add("Username", new ActionError("error.login.username")); }
// Si Champ password inférieur à 5 caractères -> erreur
if (this.password.length() < 5)
{ errors.add("Password", new ActionError("error.login.password")); }
return errors;
} |
Action
Code:
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
| public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
String result = "failure";
ActionErrors errors = new ActionErrors();
HttpSession session = request.getSession();
if (form instanceof LoginIntervenantForm){
LoginIntervenantForm loginIntervenantForm = (LoginIntervenantForm) form;
System.out.println("Start execute : " + loginIntervenantForm);
String login = loginIntervenantForm.getLogin();
String password = loginIntervenantForm.getPassword();
log.debug("login : " + login);
log.debug("password : " + password);
LoginIntervenantService loginIntervenant = new LoginIntervenantService();
System.out.println(loginIntervenant);
if(loginIntervenant.checkUser(login, password)){
Intervenant i = new Intervenant();
i.setLogin(login);
i.setPassword(password);
System.out.println("Execute OK ...");
session.setAttribute("intervenant", i);
log.debug("authentification success");
result = "success";}
else{
errors.add("Authentification", new ActionError("error.login.authentification"));
saveErrors(request,errors);
log.debug("authentification failed");
}
}
return mapping.findForward(result);
} |