Bonjour,
je suis entrain de m'initier à struts.

mon but est d'afficher dans une page, l'erreur du formulaire.

je n'utilise pas la méthode validate dans l'actionform.

mon fichier struts-config.xml

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
<?xml version="1.0" encoding="UTF-8"?>  
  <!DOCTYPE struts-config PUBLIC   
      "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"   
     "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">  
<struts-config>
	<global-exceptions>
	    <exception
	        type="com.jmd.test.struts.exception.BusinessException"
	        key="error.business"
            bundle="struts.application.message" />  
	</global-exceptions>
  <form-beans type="org.apache.struts.action.ActionFormBean">
		<form-bean name="loginForm" type="com.jmd.test.struts.data.LoginForm" />
       	<form-bean name="inscriptionForm" type="com.jmd.test.struts.data.InscriptionForm" />
 
  </form-beans>
 
  <action-mappings type="org.apache.struts.action.ActionMapping">
    <action path="/login" input="/index.jsp" scope="request"
	  name="loginForm" validate="true" type="com.jmd.test.struts.controleur.LoginAction">
      <forward name="succes" path="/accueil.jsp" redirect="false" />
      <forward name="echec" path="/index.jsp" redirect="false" />
    </action>
 
 
    <action path="/inscription" input="/error.jsp" scope="request"
	  name="inscriptionForm" validate="false" type="com.jmd.test.struts.controleur.InscriptionAction">
      <forward name="succes" path="/accueil2.jsp" redirect="false" />
    </action>
  </action-mappings>
	<message-resources key="error.message" parameter="properties.error" />
</struts-config>
mon fichier de controle

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
public class InscriptionAction extends Action{
 
	public ActionForward execute(ActionMapping mapping, 
            ActionForm form, 
            HttpServletRequest req, 
            HttpServletResponse res) throws Exception {
		String idEvent = "echec";
		if (controleFormulaire(req) == true)
			idEvent = "succes";
 
 
		return mapping.findForward(idEvent);
	}
 
 
 
	private boolean controleFormulaire (HttpServletRequest request) throws BusinessException{
		String nom = request.getParameter("nom");
		String prenom = request.getParameter("prenom");
		String email = request.getParameter("email");
 
		if (nom.equals("".trim()) && email.equals("".trim()) && prenom.equals("".trim())){
			throw new BusinessException("error.formulaireVide");
		}
		if ("ekremyilmaz@free.fr".equals(email.trim())){
			throw new BusinessException("error.mailExistant");
		}
		if ("yilmaz".equals(nom.trim())){
			throw new BusinessException("error.nomExistant");
		}
 
		return true;
 
 
 
 
	}
 
}

mon fichier data :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
public class InscriptionForm extends ActionForm{
	/**
         * 
         */
 
	private String nom;
	private String prenom;
	private String email;
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getNom() {
		return nom;
	}
	public void setNom(String nom) {
		this.nom = nom;
	}
	public String getPrenom() {
		return prenom;
	}
	public void setPrenom(String prenom) {
		this.prenom = prenom;
	}
 
	public void reset(ActionMapping mapping, HttpServletRequest request) {
		this.email = null;
		this.prenom = null;
		this.nom = null;
	}
}
maintenant lorsque j'envoi le formulaire,je suis bien redirigé vers error.jsp

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Error JSP</title>
</head>
<body>
<div style="background-color:#990000;color:#FFFFFF">
 
 
<logic:messagesPresent>
<html:messages id="error" bundle="error.message">
		      -&nbsp;<bean:message name="error"/><br/>
</html:messages>
 
</logic:messagesPresent>
</div>
</body>
</html>
mais là, il m'affiche que le bean error n'existe pas. je vous dirai c normal, mais ce que je souhaite, c'est afficher les messages d'erreurs detectés.
Or quand je remplace ça
Code : Sélectionner tout - Visualiser dans une fenêtre à part
<bean:message name="error"/>
par ça
Code : Sélectionner tout - Visualiser dans une fenêtre à part
<bean:write name="org.apache.struts.action.EXCEPTION"/>
j'obtiens dans la page error.jsp
com.jmd.test.struts.exception.BusinessException: error.formulaireVide
ce qui est normal vu que j'ai rien saisi dans mon formulaire.

mais ce que je souhaite c'est qu'il m'affiche "le formulaire est vide" car dans mon fichier properties :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
error.formulaireVide=le formulaire est vide<br/>
donc en fait ce que je ne comprend pas, c'est le bean write