Then you would repeat the same steps to figure out the directory (or reuse your variable) if you need to access it using IO and you just append "/images/" before the filename when you access it using a link/img/etc. Unless I'm still not following it really isn't all that hard.
First, thank you for your responses
Second, Yes, appending the folder to the path is no big deal but I'll explain more.
In my NetbeansProjects folder there's my application folder named ExpensesTest
under ExpensesTest there's Web folder and Build folder which has the built java after Netbeans deploys the application to the server
When I write the file it goes under Build/web directory
then when I try to access it from jsp page using getServletContext().getRealPath or application.getRealPath, the path would be:
which obviously doesn't exist.
Is there a way to move the generated file from Build to the root? or there's a way to access the file after the build? or it'll just work when the application is deployed?
getRealPath is for writing the file, then you would use a relative path to read the file. Does that make sense?
As an alternative you can store the image just about anywhere and use a servlet to handle locating and displaying the image as needed (this is highly flexible as you could then use a DB or alternate storage medium separate from the build directory). Here is some excellent code for an image servlet to handle images that are not stored within a web accessible directory: http://balusc.blogspot.com/2007/04/imageservlet.html