0

I have been following http://balusc.blogspot.in/2007/07/fileservlet.html but couldn't get it right with my code as i am not understanding much of it ...

filePath = request.getServletContext().getRealPath("")+File.separator+"images"+File.separator+"photo.jpg";
    System.out.println(filePath);
    // Get requested file by path info.
    String requestedFile = request.getPathInfo();
    System.out.println(requestedFile);
    // Check if file is actually supplied to the request URI.
    if (requestedFile == null) {
        // Do your thing if the file is not supplied to the request URI.
        // Throw an exception, or send 404, or show default/warning page, or just ignore it.
        response.sendError(HttpServletResponse.SC_NOT_FOUND); // 404.
        System.out.println("terminates");
        return;
    }

what i get out of this is the program terminates here as the requestedFile is null all the time... can anyone help me go through the code.... Any Help will be appreciated !!! Thanks in advance !!!

Roshan Shahukhal
  • 243
  • 4
  • 15

1 Answers1

3

I wrote this code on hackathon so it's not clean. You can see example here, more specifically here.

BalusC explains it better stackoverflow.com/a/8521981/660408

I created 'resources' folder in eclipse project directory and placed images there.

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String filename = request.getPathInfo().substring(1);
        File file = new File("D:\\FreeUni-enterprise\\CloudLibrary\\resources", filename);
        ...
}
Community
  • 1
  • 1
gkiko
  • 2,283
  • 3
  • 30
  • 50