Hi. I already know how to serve files (PDF, image, Zip...) to clients via a servlet. This was working when the application was deployed as a dir but when it is packed as an EAR I got FileNotFoundException. Any work around? Thanks.
Then I'm surprised that that was ever working (ear file or not).
The getContextPath method doesn't return the filesystem path, which is what java.io.File needs.
In any case, if the file you want to stream to the user is inside your webapp's directory structure, the best way to access it is with context.getResourceAsStream. This method will return a streamed version of your resource regardless of whether it is a file on the operating system or (in your case) a resource bundled in a jar, war, or ear file.
We have an example app that streams images from behind the WEB-INF directory in our CodeBarn. It's in the servlets section, look for SimpleStream.