Wednesday, 2 October 2013

File upload temp location exception in servlet

File upload temp location exception in servlet

My servlet host in free trial apache server for testing purpose. So when I
tried to upload jpeg image to my image folder in that server it gives this
error :
java.security.AccessControlException: access denied ("java.io.FilePermission"
"/usr/local/shared/tomcat/dilis/temp/upload_e1bed5d1_54a9_45e0_b1ae_26732a1441fc_00000059.tmp"
"write")
java.security.AccessControlContext.checkPermission(AccessControlContext.java:366)
How should I change temp directory to where I have access or any other way
to do it?
Here is my servlet code :
if (!((FilenameUtils.getName(item.getName()) == "") ||
(FilenameUtils.getName(item.getName()).isEmpty()))) {
String rootPath = System.getProperty("catalina.home");
File theDir = new File(rootPath + "\\webapps\\images\\" + max_id);
// if the directory does not exist, create it
if (!theDir.exists()) {
boolean result = theDir.mkdir();
if (result) {
System.out.println("DIR created");
}
}
String fieldname = item.getFieldName();
InputStream filecontent = item.getInputStream();
File f = new File(rootPath + "\\webapps\\images\\" + max_id + "\\" +
item.getName());
try {
// item.write(file);
item.write(f);
} catch (Exception ex) {
Logger.getLogger(Mobile_slt.class.getName()).log(Level.SEVERE,
null, ex);
}

No comments:

Post a Comment