Récupérer des données à partir d'une base Oracle en utilisant JSF
Salut
Mon programme consiste à récupérer des données à partir d'une base de données oracle en utilisant jsf
c'est à dire quand j'introduis le critère de recherche dans la zone de text et ensuite en cliquant sur le bouton j'affiche seulement les éléments correspondants
voici mon bean
Beansearch.java
Code:
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
|
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
/**
*
* @author utilisateur
*/
public class Beansearch extends HttpServlet {
ResultSet rs;
private List perInfoAll = new ArrayList();
private int i;
public List getperInfoAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException, SQLException {
String value = req.getParameter("cond");
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(Beansearch.class.getName()).log(Level.SEVERE, null, ex);
}
Connection con = null;
try {
con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:gmao", "pfe", "gmao");
} catch (SQLException ex) {
Logger.getLogger(Beansearch.class.getName()).log(Level.SEVERE, null, ex);
}
Statement st = null;
try {
st = con.createStatement();
} catch (SQLException ex) {
Logger.getLogger(Beansearch.class.getName()).log(Level.SEVERE, null, ex);
}
try {
rs = st.executeQuery("select username, jobposition from user_details="+value+"");
/** Creates a new instance of Beansearch */
} catch (SQLException ex) {
Logger.getLogger(Beansearch.class.getName()).log(Level.SEVERE, null, ex);
}
while(rs.next())
{
perInfoAll.add(i,new perInfo(rs.getString(1),rs.getString(2)));
i++;
}
return perInfoAll;
}
public class perInfo {
private String username;
private String jobposition;
public perInfo(String username,String jobposition) {
this.username = username;
this.jobposition = jobposition;
}
public String getusername() {
return username;
}
public String getjobposition() {
return jobposition;
}
}
/** Creates a new instance of Beansearch */
public Beansearch() {
}
} |
et se qui concerne les pages jsf j'ai utilisé 2 pages l'une pour entrer les données et l'autre pour afficher les résultats
voici le code de la page pour afficher le résultat
resultat.jsp
Code:
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
|
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form>
<h:dataTable id="dt1" value="#{Beansearch.perInfoAll}" var="item" bgcolor="#F1F1F1" border="10" cellpadding="5" cellspacing="3" rows="4" width="50%" dir="LTR" frame="hsides" rules="all" summary="This is a JSF code to create dataTable." >
<h:column>
<f:facet name="header">
<h:outputText value="First Name" />
</f:facet>
<h:outputText style="" value="#{item.username}" ></h:outputText>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Last Name"/>
</f:facet>
<h:outputText value="#{item.jobposition}"></h:outputText>
</h:column>
<f:facet name="footer">
<h:outputText value="The End" />
</f:facet>
</h:dataTable><br>
</form>
</body>
</html> |
mon problème réside au niveau de la page qui concerne l'introduction du critére de recherche
Code:
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
|
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<html>
<f:view>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form>
<input name="cond" />
<h:commandButton value="Rechercher" action = "search " actionListener="#{Beansearch.getperInfoAll}" />
</form>
</body>
</f:view>
</html> |
quand j'introduis le critère de recherche dans la page search.jsp et je clique sur le bouton recherche je ne peut pas accéder à la page qui affiche le résultat
qu'est ce que je doit ajouter pour que je puisse faire ça ?
je sait que le problème est peut être au niveau
Code:
1 2
|
<h:commandButton value="Rechercher" action = "search " actionListener="#{Beansearch.getperInfoAll}" /> |
mais je ne sait pas comment corrigé ça
Pourriez vous m'aider s'il vous plait
je vous remercie