0

localhostからhtmlページを表示するのに問題があります。これが私の方法ですがSystem.out.println("IN !")、ループに入ります(Eclipseコンソール)。http://localhost:1600/myWebPage.htmlブラウザにアドレスを入れても何も起こりませんでした。を入力した後、ブラウザにWebページまたはテキストを表示する方法を知りたいですhttp://localhost:1600/myWebPage.html。このパスは正しいですか?

public class ServerWWW {

    //localhost:1600/

    public static void main(String[] args) {

        int portServerWww = 1600;
        ServerSocket ss = null;

        try {
            ss = new ServerSocket(portServerWww);
            System.out.println("Server WWW waiting .....");

            while(true) {
                Socket s = ss.accept(); // block
                new ServiceWWW (s).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (ss != null) {
                try {
                    ss.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

class ServiceWWW extends Thread {

        private Socket s = null;
        private int counter;

        public ObslugaWWW(Socket s) {
            this.s = s;
        }



     public void run(){
        try {

           System.out.println("IN !"); //Loop
           URL url = new URL("http://localhost:1600/myWebPage.html");
           HttpURLConnection yc = (HttpURLConnection)url.openConnection();
           yc.setRequestMethod("GET");
           yc.setDoOutput(true);
           yc.connect();

           BufferedReader rd  = new BufferedReader(new InputStreamReader(yc.getInputStream()));
           StringBuilder sb = new StringBuilder();
           String line = "OK";

           while ((line = rd.readLine()) != null){
              sb.append(line + '\n');
           }

           System.out.println(sb.toString());

           yc.disconnect();

           } catch (MalformedURLException e) {
              e.printStackTrace();
           } catch (IOException e) {
           // TODO Auto-generated catch block
              e.printStackTrace();
           }

        }
}
4

0 に答える 0