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:
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:
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 :
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
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.
Partager