Store file on Tomcat Server or any other servlet container

Option 1: Get application Real path

filePath = getServletContext().getRealPath("") + "/docs/" + filename;

Option 2: Save the path in WEB.xml

filePath = getServletContext().getInitParameter("filePath") + "/docs/" + filename;

Create directory if one doesn't exists

File file = new File(filePath);
        if (!file.exists()) {
            file.mkdir();
        }