salut,
je travail sur une application avec j2EE/struts , j'utilise MyEclipse et oracle, je veux afficher le resultat d'une requete select sur une page jsp , mon problème c'est quand j'execute ça me donne la page vide
pour la connection de oracle et myeclipse marche tres bien .
voila la classe qui contien la methode
l'action :
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
98 package metier; import java.sql.*; import java.util.*; import metier.Post; public class Post { private String id; private String name; private String AdresseP; private String TelP; private String FaxP; public Post() { } public Post(ResultSet rs) throws SQLException { init(rs); } public void init(ResultSet rs) throws SQLException { this.id=rs.getString("CODEP"); this.name=rs.getString("INTITULEP"); this.AdresseP=rs.getString("ADRESSEP"); this.TelP=rs.getString("TELP"); this.FaxP=rs.getString("FAXP"); } public String getId() { return id; } public void setId(String CODEP) { this.id = CODEP; } public String getName() { return name; } public void setName(String INTITULEP) { this.name = INTITULEP; } public String getAdresse() { return AdresseP; } public void setAdresse(String ADRESSEP) { this.AdresseP = ADRESSEP; } public void setTelP(String TELP) { this.TelP = TELP; } public String getTelP() { return TelP; } public void setFaxP(String FAXP) { this.FaxP = FAXP; } public String getFaxP() { return FaxP; } public static Post[] getPost() { Vector posts=new Vector(); Statement sStat=null; String sQuery="select * from POSTE_COMPTABLE"; Connection cCon=null; try{ Class cDriverOracle=Class.forName("oracle.jdbc.driver.OracleDriver"); Driver dDriverOracle=(java.sql.Driver)cDriverOracle.newInstance(); DriverManager.registerDriver(dDriverOracle); cCon=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:azerty","administrateur","admin"); } catch(Exception e){ System.out.println("--Pbm en chargeant le driver JDBC oracle--"); e.printStackTrace(); } try{ sStat=cCon.createStatement(); ResultSet rs=sStat.executeQuery(sQuery); while( rs.next()){ Post post=new Post(rs); posts.add(post);} sStat.close(); } catch(Exception sqlE){ System.out.println("La Requête n'a pas abouti"); sqlE.printStackTrace(); } Post [] arrayPosts=new Post[posts.size()]; return (Post[])posts.toArray(arrayPosts); } }
la page 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
40
41
42
43
44
45
46
47
48
49
50
51
52 /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.yourcompany.struts.action; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import metier.*; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.yourcompany.struts.form.ListPostForm; /** * MyEclipse Struts * Creation date: 06-02-2009 * * XDoclet definition: * @struts.action path="/listPost" name="listPostForm" scope="request" validate="true" * @struts.action-forward name="success" path="/PostListing.jsp" */ public class ListPostAction extends Action { /* * Generated Methods */ /** * Method execute * @param mapping * @param form * @param request * @param response * @return ActionForward * @throws SQLException */ public ActionForward execute( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { Post [] t=Post.getPost(); request.setAttribute("depts",t); return mapping.findForward("success"); } }
merci d'avance
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 <%@ page language="java" import="metier.*" pageEncoding="ISO-8859-1"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>My JSP 'PostListing.jsp' starting page</title> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <h3><marquee> Liste des postes comptables </marquee> </h3> <table border="1" cellpadding="1" > <tr> <th> Code poste </th> <th> Nom poste </th> </tr> <% Post [] depts=(Post []) request.getAttribute("depts"); for(int i=0; i<depts.length;i++) { %> <tr> <td> <%=depts[i].getId()%> </td> <td> <%=depts[i].getName()%> </td> </tr> <% } %> </table> </body> </html>
Partager