Bonjour a tous
je travaille sur une application web qui va servir à gerer les factures d'un abonnement gsm ou fixe.
J'utilise le modèle MVC pour le developpement. La partie modèle à été traiter avec Hibernate et elle contient six classe:
- Abonnement
- Abonnement GSM
- Abonnement FIXE
- Client
- Facture
- Operateur
La classe Operateur estPour la vue, j'utilise le framework Struts
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 package mod; import java.util.Date; import java.util.List; import org.hibernate.Session; import util.HibernateUtil; public class Operateur { public List chercheClientsParMotCles(String motCle){ Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); List lesCli= session.createQuery("from CLIENT where nom:=y").setString("y", motCle).list(); return lesCli; } public Abonnement getAbonnement(Long idAb){ Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Abonnement ab=(Abonnement)session.load(Abonnement.class,idAb); ab.getFactures(); return ab; } public void addClient(Client c){ Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); session.save(c); session.getTransaction().commit(); } public void addAbonnementGSM(String numAb, String nomAb, Date dateAb, double solde, Long idClient, String fidelio){ Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Client cli=(Client)session.load(Client.class,idClient); AbonnementGSM a= new AbonnementGSM(); a.setNumAb(numAb); a.setNomAb(nomAb); a.setDateAb(dateAb); a.setSolde(solde); a.setFidelio(fidelio); cli.addAbonnement(a); session.save(a); session.getTransaction().commit(); } public void addFacture(String numFacture, Date dateFacture, double montant,boolean regle, Long idAb){ Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Abonnement a=(Abonnement) session.load(Abonnement.class,idAb); Facture f= new Facture(); f.setNumFacture(numFacture); f.setDateFacture(dateFacture); f.setMontant(montant); a.addFactures(f); session.save(f); session.getTransaction().commit(); } public void reglerFacture(Long idFact){ Session session=HibernateUtil.getSessionFactory().getCurrentSession(); session.beginTransaction(); Facture f=(Facture) session.load(Facture.class, idFact); f.setRegle(true); session.save(f); session.getTransaction().commit(); } }
Voici les fichiers que j'ai créer:
AbonnementFormActionAbonnement
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 package pres; //import java.util.Vector; import java.util.Vector; import mod.*; import org.apache.struts.action.ActionForm; public class AbonnementForm extends ActionForm{ /** * */ private static final long serialVersionUID = 1L; private Long idAb; private String action=""; private Abonnement ab; private Client cli; private Facture f=new Facture(); private Vector vect=new Vector(); static int temp; public Abonnement getAb() { return ab; } public void setAb(Abonnement ab) { this.ab = ab; } public Client getCli() { return cli; } public void setCli(Client cli) { this.cli = cli; } public static int getTemp() { return temp; } public static void setTemp(int temp) { AbonnementForm.temp = temp; } public String getAction() { return action; } public void setAction(String action) { this.action = action; } public Vector getVect() { return vect; } public void setVect(Vector vect) { this.vect = vect; } public Facture getF() { return f; } public void setF(Facture f) { this.f = f; } public Long getIdAb() { return idAb; } public void setIdAb(Long idAb) { this.idAb = idAb; } }le 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 package pres; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import mod.*; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; public class ActionAbonnement { public ActionForward execute( ActionMapping map, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { AbonnementForm af=(AbonnementForm) form; Operateur op=new Operateur(); if(af.getAction().equals("Rechercher")){ af.setAb(op.getAbonnement(af.getIdAb()) ); } if(af.getAction().equals("Regler")){ op.reglerFacture(af.getIdAb()); } return map.findForward("vueClients"); } }et finalement la vue abonnement.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 <?xml version="1.0" encoding="iso-8859-1"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <form-beans> <form-bean name="af" type="pres.AbonnementForm"/> </form-beans> <global-forwards> <forward name="vueClients" path="/vues/abonnement.jsp"/> </global-forwards> <action-mappings> <action path="/abonnement" name="af" type="pres.AbonnementAction" scope="request" /> </action-mappings> <message-resources parameter="ApplicationResources"/> </struts-config>
quand j'ouvre la page, le navigateur me dit que le path abonnement n'a pas pu etre créer.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%> <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> <!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> <html:form action="abonnement.do" method="post"> <table border="1"> <tr> <td>Entrer le numeros d'abonnement</td> <td><html:text property="idAb" value=""></html:text></td> <td><html:submit property= "action" value="Rechercher"></html:submit></td> </tr> </table> </html:form><br> <table border="1"> <tr> <td>id Abonnement</td> <td>num Abonnement</td> <td>nom Abonnement</td> <td>date Abonnement</td> <td>solde</td> <td>fidelio</td> <td>debit</td> </tr> <logic:iterate id="a" name="af" property="ab" > <tr> <td><bean:write name="a" property="idab" /></td> <td><bean:write name="a" property="numAb"/></td> <td><bean:write name="a" property="nomAb"/></td> <td><bean:write name="a" property="ateAb"/></td> <td><bean:write name="a" property="solde"/></td> <td><bean:write name="a" property="fidelio"/></td> <td><bean:write name="a" property="debit"/></td> </tr> </logic:iterate> </table> <table> <tr> <td>id Client</td> <td>nom</td> <td>email</td> <td>telephone</td> <td>ville</td> </tr> <logic:iterate id="c" name="af" property="cli" > <tr> <td><bean:write name="c" property="cli.idClient"/></td> <td><bean:write name="c" property="cli.nom"/></td> <td><bean:write name="c" property="cli.email"/></td> <td><bean:write name="c" property="cli.tel"/></td> <td><bean:write name="c" property="cli.ville"/></td> </tr> </logic:iterate> </table> <table> <tr></tr> <logic:iterate id="fact" name="af" property="f"> <tr> <td><bean:write name="fact" property="f.idFacture"/></td> <td><bean:write name="fact" property="f.numFacture"/></td> <td><bean:write name="fact" property="f.dateFacture"/></td> <td><bean:write name="fact" property="f.montant"/></td> </tr> </logic:iterate> </table> </body> </html>
merci de jeter un petit coup d'oeil à mon travail et me dire ce qui ne va pas si c'est possible.
Partager