Connexion base de donnée avec struts [Résolu]

ezzeddinehannachi 22 Messages postés vendredi 25 mai 2007Date d'inscription 19 juin 2012 Dernière intervention - 7 mai 2008 à 11:31 - Dernière réponse : ezzeddinehannachi 22 Messages postés vendredi 25 mai 2007Date d'inscription 19 juin 2012 Dernière intervention
- 7 mai 2008 à 15:51
bonjour,j'arrive pas a afficher les données de ma base.j'utilise eclipse,struts 1.2 et mysql.merci pour votre aide d'avance
code (struts-config.xml){
<?xml version= "1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">

<struts-config>
  <data-sources >
   
    <data-source type="org.apache.struts.action.DATA_SOURCE" key="gestion formation">
      <set-property property="password" value="mysql" />
      <set-property property="minCount" value="" />
      <set-property property="maxCount" value="" />
      <set-property property="user" value="root" />
      <set-property property="driverClass" value="com.mysql.jdbc.Driver" />
      <set-property property="description" value="" />
      <set-property property="url" value="jdbc:mysql://localhost:3306/gestion formation" />
      <set-property property="readOnly" value="true" />
      <set-property property="autoCommit" value="true" />
      <set-property property="loginTimeout" value="" />
    </data-source>

  </data-sources>

  <form-beans >
    <form-bean name="listeForm" type="com.yourcompany.struts.form.ListeForm" />
    <form-bean name="erreursForm" type="com.yourcompany.struts.form.ErreursForm" />

  </form-beans>

  <global-exceptions />
  <global-forwards />
 
   
      <forward name="succes" path="/form/liste.jsp" />
      <forward name="echec" path="/form/echec.jsp" />
   

 

  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
</struts-config>

}
code (ListeAction.java){
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yourcompany.struts.action;

import java.sql.ResultSet;
import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import com.yourcompany.struts.form.ListeForm;

/**
 * MyEclipse Struts
 * Creation date: 05-07-2008
 *
 * XDoclet definition:
 * @struts.action path="/liste" name="listeForm" input="/form/liste.jsp" scope="request" validate="true"
 * @struts.action-forward name="succes" path="/form/liste.jsp"
 * @struts.action-forward name="echec" path="/form/echec.jsp"
 */
public class ListeAction extends Action {
    /*
    
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response) {
        ListeForm listeForm = (ListeForm) form;// TODO Auto-generated method stub
        DataSource dataSource=this.getDataSource(request,"gestion formation");
        if(dataSource==null){
            ActionErrors erreurs=new ActionErrors();
            erreurs.add("gestion formation",new ActionError("erreur.gestion formation","La source de donnée n'a pas pu etre crée"));
            this.saveErrors(request,erreurs);
            return mapping.findForward("echec");
        }
   
    Connection connexion=null;
    Statement st = null;
    ResultSet rs=null;
    String requete=null;
    ArrayList alFormation=new ArrayList();
    try{
        connexion = (Connection) dataSource.getConnection();
        requete="select * from formation";
        st=(Statement) connexion.createStatement();
        rs=st.executeQuery(requete);
        while(rs.next()){
            alFormation.add(new String[]{
                    rs.getString("Nom"), rs.getString("Prenom")});
            }
        //rs.close();
        //st.close();
        }
    catch(Exception ex){
        ActionErrors erreurs=new ActionErrors();
        erreurs.add("gestion foemation",new ActionError("erreur.gestion formation"));
        this.saveErrors(request, erreurs);
        return mapping.findForward("echec");
                     }
    finally{
        try{
            connexion.close();
        }
        catch(Exception ignored){
           
        }
    }
    request.setAttribute("liste", alFormation);
    return mapping.findForward("succes");
   
}
}
}
code(liste.jsp){
<%@ page language="java" pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
 
<html>
    <head>
        <title>connexion</title>
    </head>
   
    liste

    <hr>
        <logic:iterate id=\"ligne\" name=\"liste\">
     <logic:notEmpty name=\"result\" scope=\"session\"/>
    ,
    </logic:iterate>
   

   
        <html:form action="/liste">
            <html:submit/><html:cancel/>
        </html:form>
   
</html>
}

à l'ecran ça m'affiche cet erreur :{
org.apache.jasper.JasperException: An exception occurred processing JSP page /form/liste.jsp at line 14

11: liste

12: <hr>
13: <table border="1">
14: <logic:iterate id="ligne" name="liste">
15: <logic:notEmpty name="result" scope="session"/>
16: <td></td>
17: </logic:iterate>

Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

cause mère

javax.servlet.ServletException: javax.servlet.jsp.JspException: Cannot find bean: "liste" in any scope
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:850)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779)
org.apache.jsp.form.liste_jsp._jspService(liste_jsp.java:148)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

cause mère

javax.servlet.jsp.JspException: Cannot find bean: "liste" in any scope
org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:935)
org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:232)
org.apache.jsp.form.liste_jsp._jspService(liste_jsp.java:99)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)

noteLa trace complète de la cause mère de cette erreur est
disponible dans les fichiers journaux de Apache Tomcat/6.0.13.

}
et dans le rapport tomcat d'eclipse, cet erreur :{
GRAVE: Initializing application data source gestion formation
java.lang.ClassNotFoundException: org.apache.struts.action.DATA_SOURCE
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
    at org.apache.struts.util.RequestUtils.applicationClass(RequestUtils.java:117)
    at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:143)
    at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:805)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
7 mai 2008 11:15:56 org.apache.catalina.core.ApplicationContext log
INFO: La servlet action est marqué comme indisponible
7 mai 2008 11:15:56 org.apache.catalina.core.StandardContext loadOnStartup
GRAVE: La servlet /connexion a généré une exception "load()"
javax.servlet.UnavailableException: Initializing application data source gestion formation
    at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:812)
    at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)
    at javax.servlet.GenericServlet.init(GenericServlet.java:212)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
    at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)
    at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:566)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
7 mai 2008 11:15:56 org.apache.coyote.http11.Http11Protocol start
INFO: Démarrage de Coyote HTTP/1.1 sur http-8080
7 mai 2008 11:15:56 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
7 mai 2008 11:15:56 org.apache.jk.server.JkMain start
INFO: Jk running ID =0 time=0/31  config=null
7 mai 2008 11:15:56 org.apache.catalina.startup.Catalina start
INFO: Server startup in 2389 ms
7 mai 2008 11:16:11 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: "Servlet.service()" pour la servlet jsp a généré une exception
javax.servlet.jsp.JspException: Cannot find bean: "liste" in any scope
    at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:935)
    at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:232)
    at org.apache.jsp.form.liste_jsp._jspService(liste_jsp.java:99)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Unknown Source)

}
Afficher la suite 

Votre réponse

1 réponse

Meilleure réponse
ezzeddinehannachi 22 Messages postés vendredi 25 mai 2007Date d'inscription 19 juin 2012 Dernière intervention - 7 mai 2008 à 15:51
3
Merci
salut, j'ai avancer un peu dans le probleme maintenant la page jsp s'affiche mais elle est vide et

dans le rapport tomcat d'eclipse, cet erreur s'affiche :
{
GRAVE: Initializing application data source gestion formation

java.lang.ClassNotFoundException: org.apache.struts.action.DATA_SOURCE

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)

at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)

at org.apache.struts.util.RequestUtils.applicationClass(RequestUtils.java:117)

at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:143)

at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:805)

at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)

at javax.servlet.GenericServlet.init(GenericServlet.java:212)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)

at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)

at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)

at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)

at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)

at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)

at org.apache.catalina.core.StandardService.start(StandardService.java:516)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

at org.apache.catalina.startup.Catalina.start(Catalina.java:566)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

7 mai 2008 15:30:05 org.apache.catalina.core.ApplicationContext log

INFO: La servlet action est marqué comme indisponible

7 mai 2008 15:30:05 org.apache.catalina.core.StandardContext loadOnStartup

GRAVE: La servlet /connexion a généré une exception "load()"

javax.servlet.UnavailableException: Initializing application data source gestion formation

at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:812)

at org.apache.struts.action.ActionServlet.init(ActionServlet.java:335)

at javax.servlet.GenericServlet.init(GenericServlet.java:212)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1161)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:981)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4042)

at org.apache.catalina.core.StandardContext.start(StandardContext.java:4348)

at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)

at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)

at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)

at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:920)

at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:883)

at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:492)

at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)

at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)

at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)

at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)

at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)

at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)

at org.apache.catalina.core.StandardService.start(StandardService.java:516)

at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)

at org.apache.catalina.startup.Catalina.start(Catalina.java:566)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)

at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)

Merci ezzeddinehannachi 3

Avec quelques mots c'est encore mieux Ajouter un commentaire

Codes Sources a aidé 125 internautes ce mois-ci

Commenter la réponse de ezzeddinehannachi

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.