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

Applets Java Discussion :

problem d'affichage de mon applet


Sujet :

Applets Java

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Avril 2007
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 1
    Points : 1
    Points
    1
    Par défaut problem d'affichage de mon applet
    bonjour, je suis entrain de créer un projet dans je doit utilisé une applet,bon dans ce projet je doit utiliser des bibliothèque externe du HttpClient, l'applet s'exécute bien dans Eclipse mais je n'arrive pas a la faire fonctionner dans le navigateur (je crois que le problème est lie au bibliothèque externe .. mais je n'arrive pas a le resoudre) .. j'ai cherché pendant 2 jours mais j'ai pas trouver des résultats.


    code source de l'applet:
    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
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.*;
    import org.apache.commons.httpclient.params.HttpMethodParams;
     
    import java.io.*;
     
    public class getSource extends JApplet{
     
      private static String url = "http://www.exemple.com/page?var=valeur";
      private JLabel label = new JLabel();
     
      public void init(){
    		this.setSize(300, 80);
    		label.setHorizontalAlignment(JLabel.CENTER);
    		label.setForeground(Color.blue);
     
    		this.getContentPane().add(label, BorderLayout.NORTH);
    		HttpClient client = new HttpClient();
    		GetMethod method = new GetMethod(url);
    		method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    		try {
    				int statusCode = client.executeMethod(method);
     
    				if (statusCode != HttpStatus.SC_OK) {
    					System.err.println("Method failed: " + method.getStatusLine());
    				}
     
    				byte[] responseBody = method.getResponseBody();
    				System.out.println(new String(responseBody));
    				label.setText(new String(responseBody));
     
    		} catch (HttpException e) {
    				System.err.println("Fatal protocol violation: " + e.getMessage());
    				e.printStackTrace();
    		} catch (IOException e) {
    				System.err.println("Fatal transport error: " + e.getMessage());
    				e.printStackTrace();
    		} finally {
    			method.releaseConnection();
    		}  
      }
    }


    code source de la page:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <html>
     
    	<body style="margin:auto;">
     
     
    		<div style="width:320px;margin:auto;margin-top:20px;border:5px solid black">
    			<applet  mayscript="true" codebase="bin/" code="getSource.class" height="80" width="300" hspace="10" vspace="10" name="first">
    			</applet>
    		</div>
     
    	</body>
    </html>


    le fichier .classpath :

    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"?>
    <classpath>
    	<classpathentry kind="src" path="src"/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-codec-1.3.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-httpclient-3.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-1.1.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-1.1.1-javadoc.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-1.1.1-sources.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-adapters-1.1.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-api-1.1.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-tests.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/junit-4.5.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/junit-4.5-src.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/junit-dep-4.5.jar"/>
    	<classpathentry kind="output" path="bin"/>
    </classpath>


    Erreur dans la console Java

    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
    java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpException
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 10 more
    j'aimerai vous signaler que je suis débutant en java donc c'est quelqu'un voulez m'aidé quel la prend en considération et merci d'avance.

  2. #2
    Futur Membre du Club
    Inscrit en
    Novembre 2008
    Messages
    4
    Détails du profil
    Informations forums :
    Inscription : Novembre 2008
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    Citation Envoyé par masix Voir le message
    bonjour, je suis entrain de créer un projet dans je doit utilisé une applet,bon dans ce projet je doit utiliser des bibliothèque externe du HttpClient, l'applet s'exécute bien dans Eclipse mais je n'arrive pas a la faire fonctionner dans le navigateur (je crois que le problème est lie au bibliothèque externe .. mais je n'arrive pas a le resoudre) .. j'ai cherché pendant 2 jours mais j'ai pas trouver des résultats.


    code source de l'applet:
    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
     
    import java.awt.BorderLayout;
    import java.awt.Color;
    import javax.swing.JApplet;
    import javax.swing.JLabel;
    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.*;
    import org.apache.commons.httpclient.params.HttpMethodParams;
     
    import java.io.*;
     
    public class getSource extends JApplet{
     
      private static String url = "http://www.exemple.com/page?var=valeur";
      private JLabel label = new JLabel();
     
      public void init(){
    		this.setSize(300, 80);
    		label.setHorizontalAlignment(JLabel.CENTER);
    		label.setForeground(Color.blue);
     
    		this.getContentPane().add(label, BorderLayout.NORTH);
    		HttpClient client = new HttpClient();
    		GetMethod method = new GetMethod(url);
    		method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    		try {
    				int statusCode = client.executeMethod(method);
     
    				if (statusCode != HttpStatus.SC_OK) {
    					System.err.println("Method failed: " + method.getStatusLine());
    				}
     
    				byte[] responseBody = method.getResponseBody();
    				System.out.println(new String(responseBody));
    				label.setText(new String(responseBody));
     
    		} catch (HttpException e) {
    				System.err.println("Fatal protocol violation: " + e.getMessage());
    				e.printStackTrace();
    		} catch (IOException e) {
    				System.err.println("Fatal transport error: " + e.getMessage());
    				e.printStackTrace();
    		} finally {
    			method.releaseConnection();
    		}  
      }
    }


    code source de la page:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    <html>
     
    	<body style="margin:auto;">
     
     
    		<div style="width:320px;margin:auto;margin-top:20px;border:5px solid black">
    			<applet  mayscript="true" codebase="bin/" code="getSource.class" height="80" width="300" hspace="10" vspace="10" name="first">
    			</applet>
    		</div>
     
    	</body>
    </html>


    le fichier .classpath :

    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"?>
    <classpath>
    	<classpathentry kind="src" path="src"/>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-codec-1.3.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-httpclient-3.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-1.1.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-1.1.1-javadoc.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-1.1.1-sources.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-adapters-1.1.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-api-1.1.1.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/commons-logging-tests.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/junit-4.5.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/junit-4.5-src.jar"/>
    	<classpathentry kind="lib" path="D:/Java/getSource/lib/junit-dep-4.5.jar"/>
    	<classpathentry kind="output" path="bin"/>
    </classpath>


    Erreur dans la console Java

    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
    java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpException
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.newInstance0(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: org.apache.commons.httpclient.HttpException
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 10 more
    j'aimerai vous signaler que je suis débutant en java donc c'est quelqu'un voulez m'aidé quel la prend en considération et merci d'avance.

    java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpException

Discussions similaires

  1. probleme d'affichage sur mon applet
    Par stc074 dans le forum Applets
    Réponses: 3
    Dernier message: 25/09/2010, 21h54
  2. probleme d'affichage d'une applet
    Par aymenroma dans le forum Applets
    Réponses: 2
    Dernier message: 30/07/2007, 10h48
  3. [Debutant] Probleme d'affichage de mon Gridview
    Par sebium dans le forum ASP.NET
    Réponses: 1
    Dernier message: 26/05/2007, 14h05
  4. affichage de mon applet Jfree : probleme
    Par altaruk dans le forum Applets
    Réponses: 1
    Dernier message: 19/05/2007, 22h06
  5. Probleme d'affichage de mon message
    Par zorba49 dans le forum ASP
    Réponses: 2
    Dernier message: 14/03/2006, 11h10

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