I don't think you really mean that you want to write the folder to the war file. A war file is an entire web application zipped into a single file.
I assume that you want to write the image into the application's directory structure. The answer is... it depends.
Depending on your container, how it's configured, and how you've deployed your application, there may or may not be a directory structure to write to.
If your container unpacks your application before deploying it, you can find the root of your application's directory structure with servletContext.getRealPath("/"). If not, this method will return null because there is no file structure.
I recommend either streaming the generated image directly to the browser if it's only going to be used once or, if you need to access it more than once, writing it to a directory outside of your web container and/or your web application's directory structure. Then, write a
servlet that can read this file and stream it to the browser. Either of these two solutions will be more robust and portable because they don't rely on the application being deployed in any particular way in order to work.
By the way:
We have an example application with a servlet that streams images in our
Code Barn.