retrieve data from database using jsf"

Discussion in 'Java' started by hib, Jun 1, 2011.

  1. hib

    hib

    Joined:
    Jun 1, 2011
    Messages:
    1
    Hello
    My program is to retrieve data from an oracle database using jsf when I enter the search criteria in the text box and I click on the button , it displays only the elements corresponding

    following is my code

    Code (Text):

    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() {
    }

    }

     
    and I used 2 jsf pages one to enter data and another to display results Here is the code of the page to display the result
    resultat.jsp
    Code (Text):

    <%@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>

     
    my problem is in the page to input data
    following is my code search.jsp
    Code (Text):

    <%@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>

     
    when I introduce the search criteria in the page search.jsp and I click the search button I can not access the page that displays the result

    what that I must add to realize this?
    I know that the problem may be in
    Code (Text):

    <h:commandButton value="Rechercher" action = "search " actionListener="#{Beansearch.getperInfoAll}" />
     
    but I do not know how to correct it
    can you help me please
    thanks
     
    hib, Jun 1, 2011
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dudu
    Replies:
    0
    Views:
    487
  2. Sebastian Fey

    JSF debugging / JSF newsgroup

    Sebastian Fey, Apr 7, 2006, in forum: Java
    Replies:
    1
    Views:
    7,833
    Danno
    Apr 7, 2006
  3. BlackIce
    Replies:
    1
    Views:
    17,319
  4. crespoh

    retrieve data from 2 database

    crespoh, Jul 28, 2005, in forum: Python
    Replies:
    3
    Views:
    4,643
    Steve Holden
    Jul 28, 2005
  5. =?Utf-8?B?c2NvdHRybQ==?=

    retrieve binary data from database and display in browser

    =?Utf-8?B?c2NvdHRybQ==?=, Mar 23, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    807
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Mar 23, 2007
Loading...

Share This Page