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 !!!

5
  • I really don't understand any of it ... is there anyway you could help me understand this !!! Commented Apr 2, 2014 at 17:53
  • So you want to read file in servlet? Commented Apr 2, 2014 at 18:01
  • yeah ! I would be glad if you could help me ! Commented Apr 2, 2014 at 18:02
  • what is the path for the image.jpg?? i mean the real path? Commented Apr 2, 2014 at 18:04
  • well first i uploaded the image into the images folder that's located exactly here "C:\Users\Roshan Shahukhal\Documents\NetBeansProjects\E-Drivers Licensing System\build\web\images\" ... now i want to retrieve that image and display in the view page ! Commented Apr 2, 2014 at 18:06

1 Answer 1

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); ... } 
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for sharing your project ! I will go through and see what comes out of it !!! anyway, thanks again !

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.