Httpserver Java отправить HTML с CSS / JS / библиотеки - PullRequest
0 голосов
/ 28 мая 2018

когда я пытаюсь загрузить страницу в путь к каталогу сервера "\ manager", он должен отправить ответ page manager.html вместе с css и различными используемыми библиотеками.Сервер отправляет страницу, единственная проблема - не выполняет присутствующий внутри javascript (с соответствующими изображениями и css).

@Override
    public void handle(HttpExchange he) throws IOException {
        String root = "html/manager";

        URI uri = he.getRequestURI();

        File file = new File(root + uri.getPath()+ ".html").getCanonicalFile();
        OutputStream os = null;
        String response = "";

        System.out.println(root + uri.getPath());

        if (!file.isFile()) {
          // Object does not exist or is not a file: reject with 404 error.
          response = "404 (Not Found)\n";
          he.sendResponseHeaders(404, response.length());
          os = he.getResponseBody();
          os.write(response.getBytes());

        } else {
          // Object exists and is a file: accept with response code 200.
          he.sendResponseHeaders(200, 0);
          os = he.getResponseBody();
          FileInputStream fs = new FileInputStream(file);
          final byte[] buffer = new byte[0x10000];
          int count = 0;
          while ((count = fs.read(buffer)) >= 0) os.write(buffer,0,count);  
          fs.close();

        }
        os.close();
    }

Вывод на консоль:

html / manager /менеджер

Вывод HTML-сервера

Открытие локального файла .html в браузере

Путь:

/ ... / Applicazione / Illumify / html / manager / manager.html

папка doc, используемая внутри manager.html

...