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
http://imageshack.us/photo/my-images/689/erreurb.png/
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:
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:
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:
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:
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> |