Create folder and upload file using servlet

Saturday, May 3, 2014

I have two web project that use tomcat..this is my directory structure..


I use commons-fileupload..this is part my code in servlet in project1

String fileName = item.getName();
String root = getServletContext().getRealPath("/");
File path = new File(root + "/uploads");

if (!path.exists()) {

File uploadedFile = new File(path + File.separator + fileName);

This will create 'uploads' folder in 'project1' but I want to create 'uploads' folder in 'webapps' because I dont want 'uploads' folder gone when I undeploy 'project1'..

I already try String root = System.getProperty("catalina.base"); but not work..

Can anyone help me...thanks in advance