How to save generated file temporarily in servlet based web application

Never use relative local disk file system paths in a Java EE web application such as new File(“filename.xml”). For an in depth explanation, see also getResourceAsStream() vs FileInputStream. Never use getRealPath() with the purpose to obtain a location to write files. For an in depth explanation, see also What does servletcontext.getRealPath(“/”) mean and when should … Read more

What does servletcontext.getRealPath(“/”) mean and when should I use it

Introduction The ServletContext#getRealPath() is intented to convert a web content path (the path in the expanded WAR folder structure on the server’s disk file system) to an absolute disk file system path. The “https://stackoverflow.com/” represents the web content root. I.e. it represents the web folder as in the below project structure: YourWebProject |– src | … Read more