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