Lire un fichier html

nollla Messages postés 14 Date d'inscription lundi 21 janvier 2008 Statut Membre Dernière intervention 8 mai 2008 - 30 avril 2008 à 20:47
indiana_jules Messages postés 750 Date d'inscription mardi 9 mars 2004 Statut Membre Dernière intervention 23 décembre 2008 - 2 mai 2008 à 08:52
bsr a tous
 j ai le code suivant qui est affiche le message suivant au cours d'excution sur mon pc malgre qu'il fonctionne sur un autre pc alors le pb reside ou?

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;


public class GetWebPage {
  public static void main(String args[]) throws IOException,
      UnknownHostException {
    String resource, host, file;
    int slashPos;


    resource = "http://www.yahoo.fr".substring(7); // skip HTTP://
    slashPos = resource.indexOf('/');
    if (slashPos < 0) {
      resource = resource + "/";
      slashPos = resource.indexOf('/');
    }
    file = resource.substring(slashPos); // isolate host and file parts
    host = resource.substring(0, slashPos);
    System.out.println("Host to contact: '" + host + "'");
    System.out.println("File to fetch : '" + file + "'");
    MyHTTPConnection webConnection = new MyHTTPConnection(host);
    if (webConnection != null) {
      BufferedReader in = webConnection.get(file);
      String line;
      while ((line = in.readLine()) != null) { // read until EOF
        System.out.println(line);
      }
    }
    System.out.println("\nDone.");
  }


  static class MyHTTPConnection {
    public final static int HTTP_PORT = 80;


    InetAddress wwwHost;


    DataInputStream dataInputStream;


    PrintStream outputStream;


   
public MyHTTPConnection(String host) throws UnknownHostException {
      wwwHost = InetAddress.getByName(host);
      System.out.println("WWW host = " + wwwHost);
    }


   
public BufferedReader get(String file) throws IOException {
     
Socket httpPipe;
      InputStream in;
      OutputStream out;
    
 BufferedReader bufReader;
      PrintWriter printWinter;
     
httpPipe = new Socket(wwwHost, HTTP_PORT);
      if (httpPipe == null) {
   
    return null;
      }
      // get raw streams
      in = httpPipe.getInputStream();
    
 out = httpPipe.getOutputStream();
      // turn into useful ones
     
bufReader = new BufferedReader(new InputStreamReader(in));
    
 printWinter = new PrintWriter(new OutputStreamWriter(out), true);
      if (in null || out null || bufReader == null || printWinter == null) {
      
 System.out.println("Failed to open streams to socket.");
        return null;
      }
    
 // send GET request
      System.out.println("GET " + file + " HTTP/1.0\n");
    
 printWinter.println("GET " + file + " HTTP/1.0\n");
    
 // read response until blank separator line
      String response;
     
while ((response = bufReader.readLine()).length() > 0) {
      
 System.out.println(response);
      }
      return bufReader;
    }
  }
}


le message:    run-main:
java.lang.NoClassDefFoundError: Servlets/GetWebPage
Exception in thread "main"
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
comment faire ?


 

1 réponse

indiana_jules Messages postés 750 Date d'inscription mardi 9 mars 2004 Statut Membre Dernière intervention 23 décembre 2008 22
2 mai 2008 à 08:52
Salut

L'erreur me semble explicite : "java.lang.NoClassDefFoundError: Servlets/GetWebPage"
Autrement, tu n'as pas dans ton class-path de ton programme, ou dans celui de ta machine un lien sur l'API des servlets.

Voili voilà

le monde a des idées : la preuve, c'est qu'il y en a de mauvaises
ne comprends pas tout, mais je parle de tout : c'est ce qui compte
0
Rejoignez-nous