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

Struts 1 Java Discussion :

Problème d'utilisation de la Servlet Action


Sujet :

Struts 1 Java

  1. #1
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut Problème d'utilisation de la Servlet Action
    Bonjour, je bosse sur un projet en Struts, et je souhaites donc créer mes premières classes et utiliser la Servlet Action.
    Voila le problème: je retombes toujours sur une page blanche lorsque je souhaites executer mon action.


    Je tapes donc l'URL : http://..../appli/test.do

    et là :page blanche.J'ai vérifié mon fichier struts-config, il est propre et sans erreurs.Le voici:
    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
     
    <?xml version="1.0" encoding="ISO-8859-1" ?>
     
    <!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
              "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
     
     
    <struts-config>
    <action-mappings>
     
    <action
    path="/test"			
    type="fr.test.Test"
    validate="true" >
    <forward name="success" path="/jsp/accueil.jsp"/>		
    </action>		
     
    </action-mappings>
     
    <controller  processorClass="org.apache.struts.tiles.TilesRequestProcessor"/>
     
     
    <message-resources parameter="MessageResources" />
     
     
      <!-- =================================================== Validator plugin -->
     
      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
        <set-property
            property="pathnames"
            value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
      </plug-in>
     
    </struts-config>

    Voici la classe test située dans le package fr:

    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
     
    package fr.test;
     
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
     
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionForward;
     
     
    public class Test extends Action{
     
    	public ActionForward execute(ActionMapping  mapping,HttpServletRequest request,HttpServletResponse response)
    		{		
    		return mapping.findForward("success");
    		}
    }


    La JSP associée:
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//FR"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
     
    <head>
     
    <title>Accueil Test</title>
    <meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
    </head>
    <body>
    Bienvenue
    </body>
    </html>


    Le problème d'après moi vient de la configuration; en effet la servlet action ne semble pas executer la classe Test.java. Si je rajoute du code JAVA dans cette classe, je n'ai jamais d'erreur lors de l'execution de test.do.


    De plus voici mon fichier Web.xml:

    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
     
    <?xml version="1.0" encoding="ISO-8859-1"?>
     
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
     
    <web-app>
     
    <taglib>
         <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
         <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
    </taglib>
     
     
     
     
      <context-param>
        <param-name>NOM_APPLICATION</param-name>
        <param-value>REMPAGA</param-value>
      </context-param>
     
      <context-param>
        <param-name>NOM_POOL</param-name>
        <param-value>REMPAGA</param-value>
      </context-param>
     
      <context-param>
        <param-name>NOM_DATA_SOURCE</param-name>
        <param-value>REMPAGA_DataSource</param-value>
      </context-param>
     
      <context-param>
        <param-name>SERVEUR_APPLICATION</param-name>
        <param-value>WEBLOGIC</param-value>
      </context-param>
     
      <context-param>
        <param-name>PROFIL</param-name>
        <param-value>AGENT</param-value>
      </context-param>
     
     
      <context-param>
        <param-name>RACINE</param-name>
        <param-value>c:/appli/grh1/conf/rempaga/</param-value>
      </context-param>
     
      <context-param>
        <param-name>LOGS</param-name>
        <param-value>c:/appli/grh1/logs/rempaga/</param-value>
      </context-param>
     
     
     <display-name>REMPAGA</display-name>
    	<servlet>
    		<servlet-name>action</servlet-name>
    		<servlet-class>
    		org.apache.struts.action.ActionServlet</servlet-class>
    		<init-param>
    			<param-name>config</param-name>
    			<param-value>/WEB-INF/struts-config.xml</param-value>
    		</init-param>		
    		<load-on-startup>1</load-on-startup>
    	</servlet>
    	<servlet-mapping>
    		<servlet-name>action</servlet-name>
    		<url-pattern>*.do</url-pattern>
    	</servlet-mapping>
    	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.htm</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    		<welcome-file>default.html</welcome-file>
    		<welcome-file>default.htm</welcome-file>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
     
     
      <mime-mapping>
        <extension>css</extension>
        <mime-type>text/css</mime-type>
      </mime-mapping>
    </web-app>

    Enfin j'ai un doute sur le classpath.peut-etre qu'il manque une indication dans ce dernier.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="src" path="WebApp/src"/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2re1.4.2_13"/>
    	<classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    	<classpathentry kind="output" path="WebApp/WEB-INF/classes"/>
    </classpath>

    Enfin voici un apercu de mon arborescence. Lors du déploiement, je prends le dossier "WebApp" que je copies/colles dans mon Weblogic.Peut etre que j'oublie de prendre certains fichiers importants au passage?




    Voila, j'espère que vous pourrez m'aider car la je sèche ...grave et moi qui aime le JAVA je commence a desesperer

  2. #2
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    C'est normal que ça ne fonctionne pas.
    Tu n'as pas défini l'ActionServlet de Struts dans le web.xml :
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
        <servlet>
        	<servlet-name>action</servlet-name>
        	<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
            <init-param>
        	  <param-name>config</param-name>
              <param-value>/WEB-INF/struts-config.xml</param-value>
        	</init-param>
    	<load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
    	<servlet-name>action</servlet-name>
    	<url-pattern>*.do</url-pattern>
        </servlet-mapping>
    Modératrice Java - Struts, Servlets/JSP, ...

  3. #3
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut
    Si tu regardes bien mon Web.xml, j'ai bien défini la Servlet Action ...(tout en bas)

  4. #4
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Désolée, je n'avais pas bien regardé.
    La fatigue du Vendredi soir sans doute.

    Mais bon, en principe, on déclare les servlets au début du web.xml.
    Ce qui me surprend, c'est que normalement, il y a un ordre à respecter pour les tags dans le web.xml.
    Tu n'as pas de message d'erreur dans la console ou la log Tomcat ?
    Modératrice Java - Struts, Servlets/JSP, ...

  5. #5
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut
    J'ai regardé les logs de mon serveur, il me dit "Web.XML malformed" à la fin du fichier(dernier ligne).

  6. #6
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Il faut mettre les tags dans l'ordre de la dtd soit, dans ton cas :
    (icon?, display-name?, description?, distributable?, context-param*, servlet*, servlet-mapping*, session-config?, mime-mapping*, welcome-file-list?, error-page*, taglib*, resource-ref*, security-constraint*, login-config?, security-role*, env-entry*, ejb-ref*)
    Modératrice Java - Struts, Servlets/JSP, ...

  7. #7
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut
    Bonjour, j'ai modifié mon Web.xml comme ca:

    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
     
    <?xml version="1.0" encoding="UTF-8"?>
     <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <servlet>
        <servlet-name>action</servlet-name>
        <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
        <init-param>
          <param-name>config</param-name>
          <param-value>/WEB-INF/struts-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
    </web-app>

    Et j'ai toujours cette erreur:
    "Descriptor web.xml malformed...Cannot find the declaration of element "web-App" <line2 column 233>

  8. #8
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut
    J'ai résolu mon problème de Web.XML, mais je tombes maintenant sur cette erreur!!

    No action instance for path /depart could be created

  9. #9
    Expert éminent

    Femme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    5 793
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : France

    Informations forums :
    Inscription : Juillet 2005
    Messages : 5 793
    Points : 7 778
    Points
    7 778
    Par défaut
    Montre-nous le mapping de l'Action de path /depart du struts-config.xml.
    Modératrice Java - Struts, Servlets/JSP, ...

  10. #10
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut
    Voici l'action en question:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    	<action
                path="/depart"			
    			type="fr.test.Test"
    			validate="true"
    			>
    	<forward name="success" path="/jsp/accueil.jsp"/>		
    	</action>
    L'action Test se trouve dans le package fr.test

  11. #11
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut
    Et voici le log du serveur quand je déploies l'appli:
    BEA-101047 4 déc. 2006 16 h 19 CET Info HTTP [ServletContext(id=9103653,name=wl_management_internal1,cont
    ext-path=/wl_management_internal1)] LogfileSearch: init

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: initialization complete

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param workingDir initialized to: C:\bea\weblogic8
    1\common\nodemanager\applisDomain\.wlnotdelete\extract\appli
    sDomain_rempaga_rempaga

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param srcCompiler initialized to weblogic.jspc

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param superclass initialized to null

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param encoding initialized to: null

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param pageCheckSeconds initialized to: 1

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param compilerval initialized to: com.sun.tools.j
    avac.Main

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param compileCommand initialized to: javac

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param compilerclass initialized to: com.sun.tools
    .javac.Main

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param packagePrefix initialized to: jsp_servlet

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: param verbose initialized to: true

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] *.jsp: init

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] strutsController: init

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=9799225,name=rempaga,context-path=/rempag
    a)] WebServiceServlet: init

    BEA-149060 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga successfully transitio
    ned from prepared to active on server applisDomain.

    BEA-149059 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga is transitioning from
    prepared to active on server applisDomain.

    BEA-149060 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga successfully transitio
    ned from unprepared to prepared on server applisDomain.

    BEA-149059 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga is transitioning from
    unprepared to prepared on server applisDomain.

    BEA-149060 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga successfully transitio
    ned from prepared to unprepared on server applisDomain.

    BEA-149059 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga is transitioning from
    prepared to unprepared on server applisDomain.

    BEA-149060 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga successfully transitio
    ned from active to prepared on server applisDomain.

    BEA-101047 4 déc. 2006 16 h 18 CET Info HTTP [ServletContext(id=8021669,name=rempaga,context-path=/rempag
    a)] *.jsp: destroy

    BEA-149059 4 déc. 2006 16 h 18 CET Info Deployer Module rempaga of application rempaga is transitioning from
    active to prepared on server applisDomain.
    une question : Weblogic initialise-til sa propre Servlet au démarrage de l'appli?
    à défaut de celle spécifiée par Struts dans struts-config.xml?

    Celà pourrait expliquer que ma Servlet Action ne tourne pas? :

  12. #12
    Membre à l'essai
    Inscrit en
    Novembre 2006
    Messages
    27
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 27
    Points : 11
    Points
    11
    Par défaut
    Mode


    j'ai trouvé enfin la solution !!


    La voici :


    Dansla méthode Test qui dérive de Action il fallait rajouter le paramètre ActionForm form. Comme ça :

    public ActionForward execute(ActionMapping mapping, --->ActionForm form <---, HttpServletRequest request,HttpServletResponse response)
    {
    return mapping.findForward("success");
    }


    La classe était mal dérivée et il n'executait pas l'action.

    Donc résolu!

    ps: merci de votre aide

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

Discussions similaires

  1. Réponses: 1
    Dernier message: 25/09/2010, 18h55
  2. Problème d'utilisation des threads dans mes servlets
    Par casho dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 08/08/2007, 19h34
  3. Problème d'utilisation de Mysql avec dev-c++
    Par Watchi dans le forum Dev-C++
    Réponses: 10
    Dernier message: 06/08/2004, 14h35
  4. [Struts][Débutant]Servlet Action non dispo ?
    Par Ho(c)ine. dans le forum Struts 1
    Réponses: 7
    Dernier message: 09/04/2004, 08h06
  5. problème d'utilisation avec turbo pascal 7.0
    Par le 27 dans le forum Turbo Pascal
    Réponses: 4
    Dernier message: 03/12/2003, 10h44

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