Fonction validate en Struts
Résolu
missihafid
Messages postés
66
Statut
Membre
-
missihafid Messages postés 66 Statut Membre -
missihafid Messages postés 66 Statut Membre -
Bonjour,
J'ai un problème c'est que la validation des input texte ça marche pas. lors de validation de formulaire, il me redirige directe dans le fichier failure.jsp.
et merci d'avance
J'ai un problème c'est que la validation des input texte ça marche pas. lors de validation de formulaire, il me redirige directe dans le fichier failure.jsp.
et voici le code de struts-config.xml
//login.jsp
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<html:html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<html:errors/>
<html:form action="login.do" method="post">
login :<html:text property="login"/><br/>
mot passe :<html:text property="pass"/><br/>
<br><html:submit value="valider"/>
</html:form>
</body>
</html:html>
/////////////////
//voici le code de classe LoginAction
package controlor;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import view.LoginForm;
public class LoginAction extends Action {
public org.apache.struts.action.ActionForward execute(
org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response) throws Exception {
LoginForm myForm=(LoginForm)form;
//String login=myForm.getLogin();
//HttpSession ses=request.getSession();
if(!myForm.getLogin().isEmpty() &&
!myForm.getPass().isEmpty()){
return mapping.findForward("success");
}else
return mapping.findForward("failure");
}
}
/////////////////////
//le code de classe LoginForm
package view;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import java.sql.*;
import javax.servlet.http.HttpServletRequest;
public class LoginForm extends ActionForm{
private String login=null;
private String pass=null;
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPass() {
return pass;
}
public void setPass(String pass) {
this.pass = pass;
}
public LoginForm() {
super();
}
// je vais tester juste pour mot de passe
public ActionErrors validate(ActionMapping mapping,HttpServletRequest req){
ActionErrors errors=new ActionErrors();
if(this.pass==null){
errors.add("pass",new ActionMessage("erreur.login"));
}
return errors;
}
}
et dans le fichier MessageResources.properties je mets erreur.login=erreur de remplissage . ce fichier est met dans src/
<form-beans>
<form-bean
name="f1"
type="view.LoginForm" />
</form-beans>
<action-mappings>
<!-- Default "Welcome" action -->
<!-- Forwards to Welcome.jsp -->
<action
path="/Welcome"
forward="/pages/Welcome.jsp"/>
<action
path="/login"
type="controlor.LoginAction"
name="f1"
scope="request"
validate="true"
input="/pages/login.jsp" >
<forward name="success" path="/pages/success.jsp" />
<forward name="failure" path="/pages/failure.jsp" />
</action>
</action-mappings>
//
<message-resources parameter="MessageResources" />
et merci d'avance
A voir également:
- Fonction validate en Struts
- Fonction si et - Guide
- Fonction miroir - Guide
- Fonction moyenne excel - Guide
- Fonction remplacer sur word - Guide
- Fonction somme excel - Guide