I have a web application with a upload form where users can upload files.
I would like to save the files in the “files” folder. And I would like this folder to be located directly under the webapp root.
Using struts2, in my uploadFileAction, I can easily set this path with String uploadDir = ServletActionContext.getServletContext().getRealPath("/files")+ "/";
But when I try to get the files, apparently my bean, which is trying to access the file, has no access to, getServletContext()and thus throws a null pointer togetRealPath
Now I'm trying to figure out how I should approach this. I heard about the spring resource, this is the way, but I can not find the relevant examples.
Is there an easy way to get my ways? I just want the rootpath for my webapp. Nothing less than that ...
source
share