to set the file path and name of the generated file
and it saves the file under Build/web directory while i want it in a directory near the JSP page. (for example www.site.com/images/)
I'm not sure I'm following you but if you just want to put it in a specific folder you can just add that to your variable you are retrieving that contains the web/build folder.
I'm not sure I'm following you but if you just want to put it in a specific folder you can just add that to your variable you are retrieving that contains the web/build folder.
Yeah, I understand your point but I'm not able to access the written file by providing the same path i got from getServletContext.getRealPath methods
I want to either access it with Java IO again or just point to it with an HTML hyperlink
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
Bookmarks