Exécution d'action répétée
Bonjour,
je développe actuellement une application web sous Eclipse. et depuis quelque temps j'ai toutes mes actions qui s'exécutent deux fois.Quant il s'agit de récupérer une liste de données,l'action s'exécute deux fois sans conséquence mais lorsque j'enregistre une nouvelle donnée le problème c'est qu'il me l'enregistre deux fois aussi.ça fais plus d'une semaine que je suis la dessus.
Est que quelqu'un peut m'aider SVP?
J'ai pas posé le codes source parce que je sais pas koi poster.
mon appli est un peu large.
Merci
Développement J2EE/struts/hibernate(problème d'exécussion d'action)
Citation:
Envoyé par
welcome_59
Poste le code qui s'exécute 2 fois, ainsi que ceux qui l'appellent.
Voici par exemple une action simple pour enregistrer ou modifier un nouvel utilisateur:
public class UserAction extends DispatchAction {
private static final Log log = LogFactory.getLog("SIT-RH");
public ActionForward addOrUpdate(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception{
ActionForward forward= mapping.findForward("success");
HttpSession session = request.getSession(false);
if (session == null) {
session = request.getSession();
}
UserForm userForm = (UserForm) form;
String nom = userForm.getNom().trim();
String prenom = userForm.getPrenom().trim();
String tel = userForm.getTel();
String fax = userForm.getFax();
String agence = userForm.getAgence().trim();
String trigramme = userForm.getTrigramme().trim();
String pwd = userForm.getPwd().trim();
int groupe = Integer.parseInt(userForm.getGroupe());
try{
//Mode Ajout
if (userForm.getIdUtil()==0){
TUserInscritHome userManager = new TUserInscritHome();
TUserInscrit user = new TUserInscrit(nom,prenom,tel,fax,agence,trigramme,pwd);
int idUser=userManager.addUser(user,groupe);
userForm.setIdUtil(idUser);
}
//Mode modif
else if(userForm.getIdUtil()!=0) {
TUserInscritHome userManager = new TUserInscritHome();
TUserInscrit user = new TUserInscrit(nom,prenom,tel,fax,agence,trigramme,pwd);
user.setIdUtil(userForm.getIdUtil());
if((userManager.updateUser(user,groupe)==true)){
forward = listeUser(mapping, form,request, response);
}
}
}
catch (Exception e) {
System.out.println( (this.getClass()).getName()+" -->>>> Pb création utilisateur : "+e.toString());
forward = mapping.findForward("fail");
}
return forward;
}
et le formulaire où j'appelle de l'action:
<script type="text/javascript">
function setHidden(value){
document.userForm.dispatch.value=value;
}
</script>
<html:form action="/addOrUpdateUser" name = "userForm" type="com.teamlog.control.form.UserForm" >
<html:hidden property = "dispatch" value="validate"/>
<html:hidden name ="userForm" property="idUtil"></html:hidden>
<div id="font_fd_bu">
<table border="0" cellpadding="0" cellspacing="0" >
<!-- Nom -->
<tr height="15"><td width="6"></td></tr>
<tr>
<td align="left" width="160px"><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.name" /><span style="color:Red;">*</span> </span></label></td>
<td colspan="1" align="left"><html:text name = "userForm" styleClass="password" tabindex="1" property="nom" maxlength="100" />
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="nom"/>
</logic:present></td>
</tr>
<!-- Prénom -->
<tr height="5"><td colspan="1"></td></tr>
<tr>
<td align="left" ><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.firstname" /><span style="color:Red;">*</span> </span></label></td>
<td colspan="1" align="left"><html:text name = "userForm" styleClass="password" tabindex="1" property="prenom" maxlength="100" />
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="prenom"/>
</logic:present></td>
</tr>
<!-- Trigramme -->
<tr height="5"><td colspan="1"></td></tr>
<tr>
<td align="left" ><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.trigramme" /><span style="color:Red;">*</span> </span></label></td>
<td colspan="1" align="left"><html:text name = "userForm" styleClass="login" tabindex="1" property="trigramme" maxlength="100" /><label for="credential" style="font-size: 11px;">@teamlog.com</label>
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="trigramme"/>
<html:errors property="trigrammeExiste"/>
</logic:present></td>
</tr>
<!-- Mot de passe -->
<tr height="5"><td colspan="1"></td></tr>
<tr>
<td align="left" ><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.pwd" /><span style="color:Red;">*</span> </span></label></td>
<td colspan="2" align="left"><html:text name = "userForm" styleClass="password" tabindex="2" property="pwd" maxlength="100" />
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="pwd"/>
</logic:present></td>
</tr>
<!-- Agence -->
<tr height="5"><td colspan="1"></td></tr>
<tr>
<td align="left" ><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.agence" /><span style="color:Red;">*</span> </span></label></td>
<td colspan="1" align="left"><html:select name = "userForm" styleClass="agence" tabindex="1" property="agence" >
<html:option value="Lannion">Lannion </html:option>
<html:option value="Nantes">Nantes </html:option>
<html:option value="Paris" >Paris </html:option>
<html:option value="Rennes">Rennes </html:option>
</html:select>
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="agence"/>
</logic:present></td></tr>
<!-- Groupe -->
<tr height="5"><td colspan="1"></td></tr>
<tr>
<td align="left" ><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.groupe" /><span style="color:Red;">*</span> </span></label></td>
<td colspan="1" align="left"><html:select name = "userForm" styleClass="groupe" tabindex="1" property="groupe" >
<html:option value="" >Groupe</html:option>
<html:option value="1" >RH</html:option>
<html:option value="2" >Commerciaux</html:option>
<html:option value="3" >Directeurs de projets</html:option>
</html:select>
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="groupe"/>
</logic:present></td></tr>
<!-- Téléphone -->
<tr height="5"><td colspan="1"></td></tr>
<tr>
<td align="left" ><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.tel"/> </span></label></td>
<td colspan="1" align="left"><html:text name = "userForm" styleClass="champ" tabindex="2" property="tel" maxlength="100" />
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="numError"/>
</logic:present></td>
</tr>
<!-- Fax -->
<tr height="5"><td colspan="1"></td></tr>
<tr>
<td align="left" ><label for="credential" style="font-size: 11px;"><span
class="Style4"> <bean:message key="addUser.fax" /> </span></label></td>
<td colspan="1" align="left">
<html:text name = "userForm" styleClass="champ" tabindex="2" property="fax" maxlength="100" />
<logic:present name="<%=Globals.ERROR_KEY%>">
<html:errors property="numErrorFax"/>
</logic:present></td>
</tr>
<tr height="10">
<td> </td>
</tr>
</table>
</div>
<div id="font_b_bu"></div>
<!-- Envoyer -->
<table cellpadding="0" cellspacing="0" border="1" style=" width:100; font-size: 12px; margin-left: 50px;">
<tr>
<td align="center" valign="top"><html:image tabindex="3" pageKey="login.validate.image" onclick="setHidden('addOrUpdate')"/></td>
</tr>
</table>
</html:form>
Et dans le fichier struts-config.xml:
<action
path="/addOrUpdateUser"
name="userForm"
validate="true"
scope="request"
parameter = "dispatch"
input="/jsp/zoneAdmin/gestion_utilisateurs/page_new_user.jsp"
type="com.teamlog.control.action.UserAction">
<forward name="success" path="page.add.ok" ></forward>
<forward name="fail" path="/jsp/erreurs/page_new_user.jsp"></forward>
<forward name = "liste_success" path="page.liste.user"></forward>
</action>