IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

Problème d'affichage à partir de la BDD


Sujet :

Servlets/JSP Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut Problème d'affichage à partir de la BDD
    Bonjour , donc j'essaye d'afficher des informations a partir des DAO de ma bd et dans ma page JSP c'est ca que ca affiche


    com.TP1.entites.EvaluationLivre@24af47f8
    com.TP1.entites.EvaluationLivre@6f9dfd98

    voici une capture de mon erreur


    ou est l'erreur ? J'ai un autre DAO dont j'ai fait les memmes demarche et l'affichage est nickel!

    voici mon code

    ma DAO

    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
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    /*
     * To change
     */
    package com.TP1.jdbc.dao;
     
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.LinkedList;
    import java.util.List;
     
    /**
     *
     * @author FoX
     */
    import com.TP1.entites.*;
     
     
     
    public class EvaluationDAO  extends Dao<EvaluationLivre> {
     
     
    public EvaluationDAO (Connection c)
    	{
                super(c);
    	}
     
     public EvaluationLivre read(int id)
            {
    	  return this.read(""+id);
    	}
       @Override     
        public EvaluationLivre read(String id) {
            try 
    		{
    			Statement stm = cnx.createStatement(); 
    			ResultSet r = stm.executeQuery("SELECT * FROM evaluation WHERE idLivre = '"+id+"'");
    			if (r.next())
    			{
    				EvaluationLivre c = new EvaluationLivre(r.getInt("id"),
    						r.getString("idProf"),
    						r.getString("idLivre"),
                                                    r.getInt("note"),
                                                    r.getString("commentaire"));
     
    				r.close();
    				stm.close();
    				return c;
    			}
    		}
    		catch (SQLException exp)
    		{
                        exp.printStackTrace();
    		}
    		return null;
    	}
     
    public List<EvaluationLivre> findEvaluation(String is){
          List<EvaluationLivre> liste = new LinkedList<EvaluationLivre>();
          try 
    		{
    			Statement stm = cnx.createStatement(); 
    			ResultSet r = stm.executeQuery("SELECT * FROM evaluation WHERE idLivre = '"+is+"'");
    			while (r.next())
    			{//(int numeroEvaluation, String idProfesseur, String idLivre, int noteLivre, String commentaireLivre
    				EvaluationLivre c = new EvaluationLivre(r.getInt("id"),
    						r.getString("idProf"),
    						r.getString("idLivre"),
                                                    r.getInt("note"),
                                                    r.getString("commentaire"));
     
     
     
     
    						liste.add(c);
                                                    }
    				r.close();
    				stm.close();
     
     
     
    		}
    		catch (SQLException exp)
    		{
                        exp.printStackTrace();
    		}
    		return liste;
            }
        @Override
        public boolean create(EvaluationLivre x) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
     
     
        @Override
        public boolean update(EvaluationLivre x) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        @Override
        public boolean delete(EvaluationLivre x) {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        @Override
        public List<EvaluationLivre> findAll() {
            throw new UnsupportedOperationException("Not supported yet.");
        }
     
        }

    Mon entitte

    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
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package com.TP1.entites;
     
    public class EvaluationLivre 
    {
        private int numeroEvaluation, noteLivre;
        private String idProfesseur, idLivre, commentaireLivre;
     
        public EvaluationLivre(int numeroEvaluation, String idProfesseur, String idLivre, int noteLivre, String commentaireLivre)
        {
           this.numeroEvaluation = numeroEvaluation;
           this.idProfesseur =idProfesseur;
           this.idLivre = idLivre;   //Constructeur
           this.noteLivre = noteLivre;
           this.commentaireLivre = commentaireLivre;     
        }
     
        public int getNumeroEvaluation()
        {
            return numeroEvaluation;
        }
     
        public void setNumeroEvaluation(int numeroEvaluation)
        { 
         this.numeroEvaluation = numeroEvaluation;   
        }
     
        public String getIdProfessuer()
        {
          return this.idProfesseur;
        }
     
        public void setIdProfesseur(String idProfesseur)
        {
          this.idProfesseur = idProfesseur;    
        }
     
        public String getIdLivre()
        {
          return idLivre;
        }
     
        public void setIdLivre(String idLivre)
        {
          this.idLivre = idLivre;    
        }
     
        public int getNoteLivre()
        {
           return noteLivre;
        }
     
        public void setNoteLivre(int noteLivre)
        {
           this.noteLivre = noteLivre;
        }
     
        public String getCommentaireLivre()
        {
          return commentaireLivre;
        }
     
        public void setCommentaireLivree(String commentaireLivre)
        {
          this.commentaireLivre = commentaireLivre;    
        }    
    }
    ma servlet

    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
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    package com.TP1.controleur;
     
    import javax.servlet.RequestDispatcher;
    import java.io.PrintWriter;
    import java.io.IOException;
    import java.util.List;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import javax.sql.DataSource;
    import javax.sql.*;
     
    import com.TP1.jdbc.Connexion;
    import com.TP1.entites.*;
     
    import com.TP1.jdbc.dao.LivresDAO;
    import com.TP1.jdbc.dao.EvaluationDAO;
     
    /**
     *
     * @author FoX
     */
    public class AfficherEvaluation  extends HttpServlet {
          @SuppressWarnings("CallToThreadDumpStack")
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException 
    { response.setContentType("text/html;charset=UTF-8");
             String  n1 = request.getParameter("isbn"); 
     
            try
              {
                 Class.forName("com.mysql.jdbc.Driver");
     
    	     Connexion.setUrl("jdbc:mysql://localhost/livres?user=root");
    	     Connection cnx = Connexion.getInstance();
    		/*
                     * 
                     */
                 EvaluationDAO ev = new EvaluationDAO(cnx); 
    	      ev.read(n1);
                //Methode des affichagess           
                List<EvaluationLivre> listEvaluation = ev.findEvaluation(n1);
     
                 request.setAttribute("livres", listEvaluation);
     
             //    request.setAttribute("evalutaion", listEvaluation);
     
                 RequestDispatcher r = this.getServletContext().getRequestDispatcher("/evaluation.jsp");
                 r.forward(request, response);             
     
           }
            catch(Exception e)
            {
                e.printStackTrace();
            }
     
     
         }
     
     
        @Override
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException 
        {
            processRequest(request, response);
        }
     
     
        @Override
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            processRequest(request, response);
        }
     
     
        @Override
        public String getServletInfo() {
            return "Short description";
        }// </editor-fold>
    }

    et ma 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
    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
     
    <%@page import="com.TP1.entites.EvaluationLivre"%>
    <%@page import="com.TP1.entites.Livre"%>
    <%@page import="java.util.List"%>
    <%@ page language="java" import="java.util.*, java.io.*, java.text.*, java.lang.*" %> 
    <%
        if (session.getAttribute("connecte")==null)  //non connecté
        {
    %>
            <jsp:forward page="login.jsp" />
    <%
        }
    %>
     
    <%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html>
    <div id="rechercher">
    <%        
            if (session.getAttribute("connecte")!=null)
            {
                out.println("<p class=\"resultat\">"+session.getAttribute("connecte")+", vous êtes connecté(e)s. "+
                "<a href=\"logout.do?action=logout\">déconnexion</a></p>");// Example de rediriction
            }        
    %>
     
     
            <%
            if (request.getAttribute("message")!=null)
            {
                out.println("<p class=\"errorMessage\">"+request.getAttribute("message")+"</p>");
            }               
            %>
    <form action="./abc.do" method="post">
               <fieldset>
                <legend>Rechercher un livre</legend>
     
                <table width="300px" align="center" style="border:0px solid #000000;background-color:#efefef;">
                    <tr><td colspan=2></td></tr>
                    <tr>
                        <td><b>Isbn:</b></td>
                        <td><input type="text" name="isbn"></td>
                    </tr> 
     
                    <tr>
                        <td><b>Mots clef_Titre:</b></td>
                        <td><input type="text" name="motscles">
                       <input type="hidden" name="action" value="afficherEvaluation"></td>
                    </tr>                                              
                    <tr>
                        <td colspan="2" align ="center"><input  type="submit" value="Soumettre" class="bouton"/></td>         
                    </tr>
                </table>
     
            </fieldset>
    </form>
          <%--  
          <div id="Menu">
            <ol>
               <li><a href="rechercher.do?action=recherche" >Rechercher par Isbn d'un livre</a></li>                  
            </ol> 
          </div>
     
            <div id="main">
              <%if (request.getParameter("action")== "recherche"){%> <p>recherche</p> 
                <%
                }
                %>
            </div>--%>
    <div id="listeLivres">  
     
     <table border="1" cellpadding="0" cellspacing="0">
    <%
     
            if (request.getAttribute("livres")!=null) // Oui 
            {
                List<EvaluationLivre> liste = (List<EvaluationLivre>)request.getAttribute("livres"); //oUI
                int n = liste.size();         
                for(int i=0; i<n; i++)
                        {
                           EvaluationLivre unLivre = liste.get(i);
                           out.println("<tr>");
                           out.println("<td>");
                           out.println(unLivre.toString());
                           out.println("</td>");
                           out.println("<tr>");
                        }
            }      
         
    %>
     
    </table>
     
          </div>
    Bassel EL-BIZRI

  2. #2
    Membre expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Points : 3 938
    Points
    3 938
    Par défaut
    C'est normal qu'il t'affiche ça,tu manipules des objets là.Que voulais tu qu'il t'affiche? .
    Essaies ça plutot :
    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
    if (request.getAttribute("livres")!=null) // Oui 
            {
                List<EvaluationLivre> liste = (List<EvaluationLivre>)request.getAttribute("livres"); //oUI
                int n = liste.size();         
                for(int i=0; i<n; i++)
                        {
                           EvaluationLivre unLivre = liste.get(i);
                           out.println("<tr>");
    out.println("<td>Numero eval:</td>");
                           out.println(unLivre.getNumeroEvaluation());
                           out.println("</td>");
    out.println("<td>Num Prof :</td>");
                           out.println("<td>");
                           out.println(unLivre.getIdProfessuer());
                           out.println("</td>");
    ...
                           out.println("<tr>");
                        }
            }
    Je te laisse déviner la suite .
    Vous avez peut être hâte de réussir et il n'y a rien de mal à cela...
    mais la patience est aussi une vertu; l'échec vous l'enseignera certainement..."

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2010
    Messages
    67
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 33
    Localisation : Canada

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2010
    Messages : 67
    Points : 61
    Points
    61
    Par défaut
    Citation Envoyé par DevServlet Voir le message
    C'est normal qu'il t'affiche ça,tu manipules des objets là.Que voulais tu qu'il t'affiche? .
    Essaies ça plutot :
    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
    if (request.getAttribute("livres")!=null) // Oui 
            {
                List<EvaluationLivre> liste = (List<EvaluationLivre>)request.getAttribute("livres"); //oUI
                int n = liste.size();         
                for(int i=0; i<n; i++)
                        {
                           EvaluationLivre unLivre = liste.get(i);
                           out.println("<tr>");
    out.println("<td>Numero eval:</td>");
                           out.println(unLivre.getNumeroEvaluation());
                           out.println("</td>");
    out.println("<td>Num Prof :</td>");
                           out.println("<td>");
                           out.println(unLivre.getIdProfessuer());
                           out.println("</td>");
    ...
                           out.println("<tr>");
                        }
            }
    Je te laisse déviner la suite .
    Mille milliard de merci ! . J'avais peur au debut je pensais ma BD est corromput
    Bassel EL-BIZRI

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Lazarus] Problème d'affichage d'une fiche à partir d'une DLL
    Par ChPr dans le forum Lazarus
    Réponses: 26
    Dernier message: 07/10/2011, 14h55
  2. probléme d'affichage d'image venant d'une bdd
    Par jolina1987 dans le forum Langage
    Réponses: 4
    Dernier message: 17/03/2010, 09h55
  3. [MySQL] Problème d'affichage malgré insertion réussie dans BDD
    Par Akushiro dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 06/07/2009, 14h30
  4. [MySQL] problème d'affichage dans tableau avec bdd Mysql
    Par sinifer dans le forum PHP & Base de données
    Réponses: 5
    Dernier message: 01/05/2009, 09h50
  5. [MySQL] Problème affichage image de ma bdd sql
    Par ljuboja78 dans le forum PHP & Base de données
    Réponses: 27
    Dernier message: 13/02/2009, 15h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo