Probleme struts

abdo77 Messages postés 3 Date d'inscription mercredi 25 mai 2005 Statut Membre Dernière intervention 16 mai 2008 - 15 mai 2008 à 15:03
ezzeddinehannachi Messages postés 22 Date d'inscription vendredi 25 mai 2007 Statut Membre Dernière intervention 19 juin 2012 - 16 mai 2008 à 15:39
Bonjour tout le monde, voila, j'ai un peti probleme qui me bloque pendant une semain, j'ai besoin de votre aide.
j'arrive pas a stocker une valeur dans ma variable de la classe actionform, ni de la réceupérer.
j'ai une page index.jsp qui contient un champ cin, et une autre page affiche.jsp qui doit m'afficher les infos liés à ce cin.
index.jsp
<%@

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" %><%@

taglib uri=
"/WEB-INF/struts-nested.tld" prefix=
"nested" %><%@

taglib uri=
"/WEB-INF/struts-template.tld" prefix=
"template" %><%@

taglib uri=
"/WEB-INF/struts-tiles.tld" prefix=
"tiles" %><%@

page language=
"java" %><

html:html locale=
"true">

<head>

<title>Authentification
</title>

<html:base/>

</head>

<body bgcolor=
"white">

<html:form action=
"main" >

<html:text property=
"cin" size=
"20" maxlength=
"20"/>

<html:submit property=
"submit" value=
"OK"/>

</html:form>

</body></

html:html>

et la page affiche.jsp

<%@

page language =
"java" contentType=
"text/html; charset=ISO-8859-1"

pageEncoding =
"ISO-8859-1"%>
<!

DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><

html><

head><

meta http-equiv=
"Content-Type" content=
"text/html; charset=ISO-8859-1"
> <

title>Insert title here
</title
></

head><

body><%

String nom =(String)request.getAttribute(

"nom");String prenom= (String)request.getAttribute(

"prenom" );

%>

</

body>nom:

<% =nom
%>
<

br>prenom:
<%= prenom
%>
</

html>

la classe Form bean qui etend actionform

package med.dao;
import org.apache.struts.action.*;
import javax.servlet.http.*;import org.apache.struts.action.ActionForm;

public class Formbean extends ActionForm {
 private int cin;
 public int getCin()
 {
  
  return cin;
 }
 void setCin(int cin)
{this.cin =cin;
 
}
 }

la classe mon_action qui étend Acion

package med.action;

import java.io.IOException;

import org.apache.struts.action.*;
import javax.servlet.http.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.HibernateException;
import med.dao.Client;
import med.dao.Formbean;
import med.managers.ClientManager;

public class Mon_action extends Action{
  public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) throws IOException,ServletException,Exception {
   
   Formbean formulaire=(Formbean) form;
   //
      
   System.out.println("cin="+formulaire.getCin()); // ici m'affiche 0
    return mapping.findForward("ok");
  
  }
}

Merci de m'aider à résoudre ce probleme.

nb: je travaille avec eclipse 3.3.2
pour les fichiers .class, il les mis pas dans web-inf/class, mais dans autre dossier build dans la racine de l'application.

1 réponse

ezzeddinehannachi Messages postés 22 Date d'inscription vendredi 25 mai 2007 Statut Membre Dernière intervention 19 juin 2012
16 mai 2008 à 15:39
salut,
dans la classe Bean tu dois ajouter la methode validate cette methode a comme role la verification de la validité de l'attribut CIN en suite elle va retourener au controleur struts la liste des erreurs ( tu test si le cin est valide ou non).
ensuite dans la classe action tu dois ajouter dans la methode execute : request.setAttribute("cin",formulaire.getCin());
et je sais pas si tu as oublier de nous montrer ton fichier struts-config.xml ou bien tu ne la pas creer en tout cas dans ce fichier tu dois ajouter le nom de la classe bean qui contient les données de ton formulaire,le nom de la classe action chargée de traiter le formulaire et le nom de ttes les vues qui seront renvoyées en reponse  exp:

struts-config>

 <data-sources/>

[# -]<form-beans>

 <form-beanname= " formulaireForm "
type ="com.yourcompany.struts.form.FormulaireForm" />

 </form-beans>

 <global-exceptions/>

 <global-forwards/>

[# -]<action-mappings>

[# -]<action attribute= " formulaireForm "
input ="/form/formulaire.jsp" name= " formulaireForm "
path ="/formulaire" scope= " request " type ="com.yourcompany.struts.action.FormulaireAction">

 <forwardname= " reponse "
path ="/form/reponse.jsp" />

 </action>

 </action-mappings>

 <message-resourcesparameter="com.yourcompany.struts.ApplicationResources" />

 </struts-config>


En esperant t'avoir aidé 
0
Rejoignez-nous