This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I need to display some pdf files which are sitting in a sub-folder inside WEB-INF. The path to the pdf is passed as a parameter from a jsp. The problem I am having is that instead of looking at the context path of my web-app, servlet is trying to load the pdf from the absolute path. For example, if the I pass the path /WEB-INF/HTMLHelp/common/sample.pdf, it goes to my hard drive and tries to look up c: \WEB-INF\HTMLHelp\common\sample.pdf instead of going to the root of my application. Please let me know what I am doing wrong. Thanks in advance
String filename =(String)request.getParameter("url"); ... File pdf= new File(filename);
It's doing exactly what you are telling it to do. What would make you think that the File object would somehow magically detect that you want to make the filename you pass to it relative to another folder?
You need to tell the File object the complete path to the file you want to open.
Hint: check out the ServletContext.getRealPath() method. [ July 25, 2006: Message edited by: Bear Bibeault ]