bonjour ,
je travaille avec struts2 et jdom sous eclipse
mon fichier struts.xml (controleur)
contient cette action
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <action name="AfficherDocAction" class="beanAction.AfficherDocAction"> <result name="afficher">./jsp/affichage.jsp</result> <result name="success">./jsp/resultat.htm</result> </action>
et voila l'actionbean
et un petit formulaire qui contient un seul bouton afficher Docs
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 package beanAction; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Iterator; import java.util.List; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamSource; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; import org.jdom2.transform.JDOMResult; import com.opensymphony.xwork2.ActionSupport; public class AfficherDocAction extends ActionSupport { private static final long serialVersionUID = 1L; private String titre; private String creator; private String subject; private String description; private String date; static Element racine = new Element("documents"); static Document document = new Document(racine); public String execute() throws Exception { // On cr�e une instance de SAXBuilder SAXBuilder sxb = new SAXBuilder(); try { Document jDomDoc = sxb.build(new File("C:/Documents and Settings/Administrateur/Mes documents/workspace/GED-1.1/ressources/documents.xml")); outputXSLT(jDomDoc, "C:/Documents and Settings/Administrateur/Mes documents/workspace/GED-1.1/ressources/fichier.xsl"); } catch (Exception e) { e.printStackTrace(); } return null; } // Exception si le fichier est mal form� private void outputXSLT(Document jDomDoc, String fichierXSL) { // TODO Auto-generated method stub // TODO Auto-generated method stub /*Document JDOMResult, résultat de la transformation TraX */ JDOMResult documentJDOMSortie = new JDOMResult(); /* Document JDOM après transformation */ Document resultat = null; try{ /* On définit un transformer avec la source XSL qui va permettre la transformation */ TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(new StreamSource(fichierXSL)); /* On transforme le document JDOMEntree grâce à notre transformer. La méthoded transform() prend en argument le document d'entree associé au transformer et un document JDOMResult, résultat de la transformation TraX */ transformer.transform(new org.jdom2.transform.JDOMSource(jDomDoc), documentJDOMSortie); /* Pour récupérer le document JDOM issu de cette transformation, il faut utiliser la méthode getDocument() */ resultat = documentJDOMSortie.getDocument(); /* On crée un fichier xml corespondant au résultat */ XMLOutputter outputter = new XMLOutputter(Format.getPrettyFormat()); outputter.output(resultat, new FileOutputStream("C:/Documents and Settings/Administrateur/Mes documents/workspace/GED-1.1/WebContent/jsp/resultat.htm")); } catch(Exception e){} }}
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 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib prefix="s" uri="/struts-tags"%> <!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>Affichage Doc</title> </head> <body> <s:form action="AfficherDocAction" method="post" > <s:submit type="submit" value="Afficher Docs"></s:submit> </s:form> </body> </html>
la source : j'ai un fichier xml qui contient des document , et aussi un fichier xsl qui me permet de transformer mon fichier xml en fichier html
je vais les presenter l'un a l'autre
document.xml
fichier.xsl
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 <?xml version="1.0" encoding="UTF-8"?> <documents> <document> <titre>document1</titre> <creator>yassine</creator> <subject>java</subject> <description>cours java</description> <date>12/08/2012</date> </document> <document> <titre>document2</titre> <creator>ahmed</creator> <subject>dot net</subject> <description>cours dot net</description> <date>11/09/2012</date> </document> <document> <titre>document3</titre> <creator>kawtar</creator> <subject>application mobiles</subject> <description>cours android</description> <date>12/11/2013</date> </document> </documents>
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 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <head> <title>Resultats</title> </head> <body> <table border="1" width="80%"> <tr> <th>Title</th> <th>Creator</th> <th>Subject</th> <th>Description</th> <th>Date</th> </tr> <xsl:for-each select="documents/document"> <tr> <td><xsl:value-of select="titre"/></td> <th><xsl:value-of select="creator"/></th> <th><xsl:value-of select="subject"/></th> <th><xsl:value-of select="description"/></th> <th><xsl:value-of select="date"/></th> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
fichier generé
resultat.htm
quand je clique sur le bouton du formulaire affichage.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
34
35
36
37
38
39 <?xml version="1.0" encoding="UTF-8"?> <html> <head> <title>Resultats</title> </head> <body> <table border="1" width="80%"> <tr> <th>Title</th> <th>Creator</th> <th>Subject</th> <th>Description</th> <th>Date</th> </tr> <tr> <td>document1</td> <th>yassine</th> <th>java</th> <th>cours java</th> <th>12/08/2012</th> </tr> <tr> <td>document2</td> <th>ahmed</th> <th>dot net</th> <th>cours dot net</th> <th>11/09/2012</th> </tr> <tr> <td>document3</td> <th>kawtar</th> <th>application mobiles</th> <th>cours android</th> <th>12/11/2013</th> </tr> </table> </body> </html>
je trouve que le fichier resultat.htm est créer dans l'endroit ou il est indiqué , c normalec pa ca le blm
je veux que le fichier resultat.htm saffiche directement dans eclipse
cette action avec result name="success" permet accéder a la page resultat.htm mais dans l'execution il ne se passe rien il crée juste le fichier resultat.htm
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 <action name="AfficherDocAction" class="beanAction.AfficherDocAction"> <result name="afficher">./jsp/affichage.jsp</result> <result name="success">./jsp/resultat.htm</result> </action>
j'espère que j'ai bien expliquer mon probleme pour que vous puissez m'aider
Merci a vous tous ^^
Partager