Bonjour,

Je suis débutante et j'esaie de réaliser une application avec struts et mysql. J'ai la page table_pays.jsp qui affiche toutes les lignes de la table PAYS (la ligne de la table est du type "id,nom") de ma base de données. Au bout de chaque ligne j'ai ajouté un lien "modifier" et un lien "supprimer" ainsi qu'à la fin du tableau un bouton "ajouter".

Maintenant voila je se que je souhaiterai faire. Je voudrais que quand on appuie sur le bouton "modifier" on arrive sur la page pays.jsp avec le nom du pays choisi écrit dans le champ nom. Si on appuie sur le bouton "ajouter" on arrive sur la meme page mais cette fois le champ est vide.

J'ai déjà essayer pas mal de chose mais rien n'a fonctionné. L'idée c'est de rajouter un attribut id à l'url. ensuite dans mon action InfoPaysAction, si l'id est egal à zero (on a appuié sur le bouton "ajouter") alors dans ma requete je retourne un pays avec un nom vide. Sinon je retourne le pays correspondant à l'id de l'url.

Mais quand j'execute mon code j'ai l'erreur suivante :
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
 
ype 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: /vues/pays.jsp(19,68) Symbole égal (equal) attendu
	org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
	org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
	org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:86)
	org.apache.jasper.compiler.Parser.parseAttribute(Parser.java:193)
	org.apache.jasper.compiler.Parser.parseAttributes(Parser.java:143)
	org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1328)
	org.apache.jasper.compiler.Parser.parseElements(Parser.java:1564)
	org.apache.jasper.compiler.Parser.parseBody(Parser.java:1793)
	org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1060)
	org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:1367)
	org.apache.jasper.compiler.Parser.parseElements(Parser.java:1564)
	org.apache.jasper.compiler.Parser.parse(Parser.java:126)
	org.apache.jasper.compiler.ParserController.doParse(ParserController.java:211)
	org.apache.jasper.compiler.ParserController.parse(ParserController.java:100)
	org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:146)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
	org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
	org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
	org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
	org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
	org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
	org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
	org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1001)
	org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:560)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:209)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	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.9.
Ca vient de ma façon de mettre la valeur du nom du pays dans le champ, mais je ne sais pas comment régler le problème. J'ai vu des exemples qui utilisent l'écriture ${infoPays.nom} mais si je fais ça alors tomcat hurle en disant que le bean infoPays n'est pas définit dans le scope.


Le deuxième probleme, c'est que du cout, je dois gérer deux actions différentes sur un même bouton. Soit faire appel à l'action AjoutPaysAction soit à l'action ModifierPaysAction. Comment puis je faire ca? Pour l'instant mon bouton ne gère que l'ajout, ne sachant pas comment je peux le parametrer.

Voici le code de la page table_paus.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
25
26
27
28
29
30
31
32
33
 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
 
<html>
	<head>
		<title>Table pays</title>
	</head>
	<body>
		<h2>Table PAYS</h2>
		<hr>
		<html:errors/>
		<table border="1">
		       <tr>
				<td>id</td>
				<td>nom</td>
				<td></td>
				<td></td>
			</tr>
			<logic:iterate id="item" name="pays">
				<tr>
					<td><bean:write name="item" property="id"/></td>
					<td><bean:write name="item" property="nom"/></td>
					<td><a href="pays.do?id=<bean:write name="item" property="id"/>">modifer</a></td>
					<td><a href="supprimerPays.do?id=<bean:write name="item" property="id"/>">Suppirmer</a></td>
				</tr>
			</logic:iterate>
		</table>
		<p><br/>
		<html:button property="btnAjouter" value="Ajouter" onclick="javascript:location.href='pays.do?id=0'"/>
	</body>
</html>
voici le code de la page pays.jsp (celle ou l'erreur apparait):
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
 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
 
<html>
	<meta http-equiv="pragma" content="no-cache">
	<head>
		<title>Pays - formulaire</title>
	</head>
 
 
	<body>
		<center>
			<h2>Gerer un pays</h2>
			<hr>
		  	 <html:form action="/paysValide">
				<table>
					<tr>
						<td>Nom du pays</td>
						<td><html:text property="nom" value="<bean:write name="infoPays" property="nom"/>"/></td>
					</tr>
					<tr>
						<td><html:submit value="Ajouter"/></td>
 
					</tr>
				</table>
			</html:form>
		</center>
	</body>
</html>
Code de l'action InfoPaysAction.java
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
 
import java.io.IOException;
import java.util.Collection;
 
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;
 
 
public class InfoPaysAction extends Action{
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IOException,ServletException {
 
		PaysBean p = new PaysBean();
		int find = p.findByPrimaryKey(Integer.parseInt(request.getParameter("id")));
		if(find == 0){
			p.setNom("coucou");
		}
		request.setAttribute("infoPays", p);
		return mapping.findForward("pays");
	}
 
}
voici le code du 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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
<?xml version="1.0" encoding="ISO-8859-1" ?>
 
<!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>
  <form-beans>
    <form-bean
       name="frmConnection"
       type="ConnectionBean"
    />
    <form-bean
       name="frmPersonne"
       type="PersonneBean"
    />
    <form-bean
       name="frmVille"
       type="VilleBean"
    />
    <form-bean
       name="frmPays"
       type="PaysBean"
    />
    <form-bean
       name="frmOperation"
       type="OperationBean"
    />
</form-beans>
 
<action-mappings>
  <action
     path="/connectionValide"
     name="frmConnection"
     scope="session"
     validate="true"
     input="/erreursConnection.do"
     type="ConnectionAction">
    <forward name="information" path="/information.do"/>
    <forward name="echec" path="/echecConnection.do"/>
    <forward name="administration" path="/administration.do"/>
  </action>
 
  <action
     path="/operationValide"
     name="frmOperation"
     scope="session"
     validate="true"
     input="/echecOperation.do"
     type="OperationAction">
    <forward name="succesOperation" path="/succesOperation.do"/>
  </action>
 
  <action path="/affPays" type="PaysAction">
    <forward name="tablePays" path="/tablePays.do"/>
  </action>
 
  <action path="/infoPays" type="InfoPaysAction">
	<forward name="pays" path="/pays.do"/>
  </action>
 
  <action path="/supprimerPays" type="SupprimerPaysAction">
	<forward name="tablePays" path="/tablePays.do"/>
  </action>
 
  <action
     path="/paysValide"
     name="frmPays"
     scope="session"
     validate="true"
     input="/tablePays.do"
     type="AjoutPaysAction">
    <forward name="tablePays" path="/tablePays.do"/>
  </action>
 
 
  <action forward="/vues/echec_connection.jsp" path="/echecConnection"/>
  <action forward="/vues/information.jsp" path="/information"/>
  <action forward="/vues/connection.jsp" path="/connection"/>
  <action forward="/vues/administration.jsp" path="/administration"/>
  <action forward="/vues/table_ville.jsp" path="/tableVille"/>
  <action forward="/vues/table_pays.jsp" path="/tablePays"/>
  <action forward="/vues/table_personne.jsp" path="/tablePersonne"/>
  <action forward="/vues/pays.jsp" path="/pays"/>
  <action forward="/vues/ville.jsp" path="/ville"/>
  <action forward="/vues/personne.jsp" path="/personne"/>
  <action forward="/vues/operation.jsp" path="/operation"/>
  <action forward="/vues/echec_operation.jsp" path="/erreursOperation"/>
  <action forward="/vues/succes_operation" path="/succesOperation"/>
 
</action-mappings>
<message-resources parameter="ressources.personneressources"/>
</struts-config>
 
 
Merci de votre aide