Forums Rue-Montgallet.com
Rue-Montgallet.comRue-Hardware.comRue-Occasion.comRue-DVD.comRue-Jeuxvideo.comRue-AudioVideo.comRue-Telephone.comForums
S'inscrire | S'identifier |
| Recherche avancée | Aide
 
 

Achat - Vente Divers : Hisokasama, bucheron-atomik et 29 utilisateurs inconnus

 Mot :   Pseudo :  
 
Bas de page
Auteur
 Sujet :

Problème avec les action de Struts

 
n°17545
kevin752
guigui
Profil : Jeune recrue
Posté le 21-09-2006 à 13:12:36  profilanswer
 

Bonjour,
 
J'ai quelques soucis avec les action Struts.  
 
En effet, j'aurais voulu savoir si quelqu'un connait des liens qui peuvent me permettre de mettre en place une application ayant une page de remplissage(jsp1), une action(jsp1Action)qui appelle les methodes metiers et affiche des resultats(avec des variables nouvelles) dans une nouvelle vue(jsp2).
Explication:
Alors j'ai deux pages jsp.
jsp1 est geree par jsp1Form et jsp1Action
j'arrive à récuperer des données de jsp1 et les afficher dans jsp2.
Parcontre, lorsque je crée une variable dans mon action jsp1Action et que je tente d'afficher le résultat dans jsp2, il ya une erreur qui me demande de rajouter des getter pour cette variable dans le formulaire jsp1Form. Ce que j'ai fais, mais rien a changé. La même erreur revient que j'ajoute ou pas des methodes get et set dans jsp1Form.
 
Je vous en prie, quelqu'un peut-il m'aider???
Merci d'avance en tout cas.
 
Kevin.

n°17567
kevin752
guigui
Profil : Jeune recrue
Posté le 24-09-2006 à 18:04:49  profilanswer
 

////////////////My JSP1 Page////////////////////////////////////
 
<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>  
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
 
<html>  
 <head>
  <title>Module 1</title>
 </head>
 <body>
 <DIV > Module 1</DIV>
  <html:form action="/module1">
   champ1 : <html:text property="champ1"/><br/>
   champ2 : <html:text property="champ2"/><br/>
   Faire un choix: <bean:define id="ids" scope="session" name="module1Form" property="lesChoix" />
   <html:select property="choix">
    <html:options collection="ids" property="value" labelProperty="label" />
   </html:select>
   <br><br>
   <html:submit/><html:cancel/><br>
   <hr>
  </html:form>
 </body>
</html>
 
////////////////////////My actionForm//////////////////////////////////////
package myPackage.form;
 
import java.util.ArrayList;
 
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.LabelValueBean;
 
/**
 * MyEclipse Struts Creation date: 09-10-2006
 *  
 * XDoclet definition:
 *  
 * @struts.form name="module1Form"
 */
public class Module1Form extends ActionForm {
 
 // --------------------------------------------------------- Instance
 // Variables
 
 /** champ2 property */
 private String champ2;
 
 /** champ1 property */
 private int champ1;
 
 /** choix property */
 private String choix;
 
 ArrayList lesChoix = new ArrayList();
 
 // --------------------------------------------------------- Methods
 
 /**
  * Method validate
  *  
  * @param mapping
  * @param request
  * @return ActionErrors
  */
 public ActionErrors validate(ActionMapping mapping,
   HttpServletRequest request) {
 
  // TODO Auto-generated method stub
  return null;
 }
 
 /**
  * Method reset
  *  
  * @param mapping
  * @param request
  */
 public void reset(ActionMapping mapping, HttpServletRequest request) {
  // initialisation de la liste des articles de la liste déroulante
  this.lesChoix.clear();
  /*
   * remplir la list:lesChoix, a partir de la base de données
   */
  lesChoix.add(new LabelValueBean("choix1", "choix1" ));
  lesChoix.add(new LabelValueBean("choix2", "choix2" ));
  lesChoix.add(new LabelValueBean("choix3", "choix3" ));
  lesChoix.add(new LabelValueBean("choix4", "choix4" ));
 }
 
 
 /**
  * @return Returns the lesChoix.
  */
 public ArrayList getLesChoix() {
  return lesChoix;
 }
 
 /**
  * @param lesChoix The lesChoix to set.
  */
 public void setLesChoix(ArrayList lesChoix) {
  this.lesChoix = lesChoix;
 }
 
 /**
  * Returns the champ2.
  *  
  * @return String
  */
 public String getChamp2() {
  return champ2;
 }
 
 /**
  * Set the champ2.
  *  
  * @param champ2
  *            The champ2 to set
  */
 public void setChamp2(String champ2) {
  this.champ2 = champ2;
 }
 
 /**
  * Returns the champ1.
  *  
  * @return String
  */
 public int getChamp1() {
  return champ1;
 }
 
 /**
  * Set the champ1.
  *  
  * @param champ1
  *            The champ1 to set
  */
 public void setChamp1(int champ1) {
  this.champ1 = champ1;
 }
 
 /**
  * Returns the choix.
  *  
  * @return String
  */
 public String getChoix() {
  return choix;
 }
 
 /**
  * Set the choix.
  *  
  * @param choix
  *            The choix to set
  */
 public void setChoix(String choix) {
  this.choix = choix;
 }
 
}
////////////////////////////////My action class///////////////////////////////////
 
package myPackage.action;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import myPackage.form.Module1Form;
 
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
 
/**  
 * MyEclipse Struts
 * Creation date: 09-10-2006
 *  
 * XDoclet definition:
 * @struts.action path="/module1" name="module1Form" input="/module1.jsp" validate="true"
 * @struts.action-forward name="default" path="/module1.jsp" redirect="true"
 */
public class Module1Action extends Action {
 
 // --------------------------------------------------------- Instance Variables
 
 // --------------------------------------------------------- Methods
 
 /**  
  * Method execute
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 public ActionForward execute(
  ActionMapping mapping,
  ActionForm form,
  HttpServletRequest request,
  HttpServletResponse response) {
  Module1Form module1Form = (Module1Form) form;
  // TODO Auto-generated method stub
  //request.getSession().setAttribute("modul1",form);
  //faire ton traitement ici à partir de donner du formulaire form, en utilisant  
  //les méthodes de la classe de traitement que tu as développé  
  int champ1=module1Form.getChamp1();
  int myData=2*champ1;;
  request.setAttribute("myData", myData);
  return mapping.findForward("resultat" );
 }
 
}
 
//////////////////////////////////////My struts-config////////////////////////////////////////
 
<struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="module1Form" type="myPackage.form.Module1Form" />
 
  </form-beans>
 
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
       attribute="module1Form" input="/module1.jsp" name="module1Form" path="/module1"
       type="myPackage.action.Module1Action">
      <forward name="resultat" path="/module2.jsp" redirect="true"/>
    </action>
  </action-mappings>
  <message-resources parameter="myPackage.ApplicationResources" />
</struts-config>
 
///////////////////////My second page JSP///////////////////////////////////////////////////
 
<%@ page language="java"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean"%>  
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic"%>
 
<html>
 <head>
  <title>Module 2</title>
 </head>
 <body>
  <DIV > Module 2</DIV>
  <html:form action="/module1">
 first data <font color="blue"><bean:write name="module1Form" property="champ1"/></font> <br>
 second data <font color="blue"><bean:write name="module1Form" property="champ2"/></font><br>
 Your choice: <font color="blue"><bean:write name="module1Form" property="choix"/></font>
 <!-- My new data -->
 <td align="left" width="50%">    
  My new data :<bean:write name="module1Form" property="mydata"/></td>
  </html:form>
 </body>
</html>
 
//////////////////////////////the error/////////////////////////////////////////////////
 
Etat HTTP 500 -  
 
type Rapport d'exception
message  
description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
exception  
org.apache.jasper.JasperException: Exception in JSP: /module2.jsp:18
 
15:  Your choice: <font color="blue"><bean:write name="module1Form" property="choix"/></font>
16:  <!-- My new data -->
17:  <td align="left" width="50%">    
18:   My new data :<bean:write name="module1Form" property="mydata"/></td>
19:   </html:form>
20:  </body>
21: </html>
 
 
Stacktrace:
 org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
cause mère  
javax.servlet.ServletException: No getter method for property mydata of bean module1Form
 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858)
 org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791)
 org.apache.jsp.module2_jsp._jspService(module2_jsp.java:77)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
cause mère  
javax.servlet.jsp.JspException: No getter method for property mydata of bean module1Form
 org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:973)
 org.apache.struts.taglib.bean.WriteTag.doStartTag(WriteTag.java:225)
 org.apache.jsp.module2_jsp._jspx_meth_bean_write_3(module2_jsp.java:196)
 org.apache.jsp.module2_jsp._jspx_meth_html_form_0(module2_jsp.java:112)
 org.apache.jsp.module2_jsp._jspService(module2_jsp.java:67)
 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de Apache Tomcat/5.5.17.
 
Apache Tomcat/5.5.17
 


Aller à :
Ajouter une réponse