1

I have a simple web server that I need to serve files from the external drive so the URL would be something like localhost:8080/map/landing.html. This is the serve method that is invoked when you change URLs:

 @Override
public Response serve(IHTTPSession session) {

    String mime_type = NanoHTTPD.MIME_HTML;
    Method method = session.getMethod();
    String uri = session.getUri();

    Log.i("myTag", uri);

    String answer = "";
    try {

        FileReader filePath = new FileReader(root.getAbsolutePath() + uri);

        Log.i("tag2", root.getAbsolutePath() + uri);

        BufferedReader reader = new BufferedReader(filePath);
        String line = "";
        while ((line = reader.readLine()) != null) {
            answer += line;
        }
        reader.close();

    } catch(IOException ioe) {
        Log.w("Httpd", ioe.toString());
    }

    Log.i("answerTag", answer);

    return new NanoHTTPD.Response(answer);

}

As of now, this method will take me to other pages when I click on links but the images, CSS, javascript is not working on the pages. I am not too familiar with networking and writing web servers. Can anyone help me to get on the right track? I read some stuff online and I believe I have to set the assets to the context of the URI's returned. Any help is appreciated, thank you

Vishal Yadav
  • 3,642
  • 3
  • 25
  • 42
Billy Kong
  • 31
  • 4
  • I suppose you are to declare the mime-type for those files. Browser needs to know what to do with them. – arjun Feb 23 '18 at 15:12

0 Answers0