begin process at 2008 09 06 19:55:30
1 237 936 membres
318 nouveaux aujourd'hui
14 314 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : lire un fichier html [ Divers / Général ] (Nollla)

lire un fichier html le 30/04/2008 20:47:24

Nollla

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 ?

 


Re : lire un fichier html le 02/05/2008 08:52:50

indiana_jules
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à

[#Tout le monde a des idées : la preuve, c'est qu'il y en a de mauvaises]
[#Je ne comprends pas tout, mais je parle de tout : c'est ce qui compte]


Classé sous : java, out, io, import, host

Participer à cet échange

Pub



Appels d'offres

CalendriCode

Septembre 2008
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
2930     

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS