views:

27

answers:

2

I wrote servlet that writes an image to the root directory of my app and then delivers it to client when it gets GET request. Everything works fine when i test it in Eclipse with jetty (came with GWT plugin). But when i move it to Tomcat, i get filenotfound exception (because image is not written at all so it can't be returned to client). Is this problem with permissions for writing files?

I added this to catalina.policy file, but it's not helping either (webui is folder of my application):

grant { 
   permission java.io.FilePermission "${catalina.home}/webapps/webui/","read,write,delete";
   permission java.io.FilePermission "${catalina.home}/webapps/webui/*","read,write,delete";
    };
+2  A: 

Modifying the security policy won't help with this; if it was a policy problem, you'd get a SecurityException rather than an FileNotFoundException.

The latter indicates that the Java process is trying to open a file handle in the appropriate mode, but is being denied by the operation system. The most likely cause of this is that the file (or parent directory) is not writable by the user that the Java process is executing as.

Have a look at the permissions on the folders you're trying to write to, and in particular look up the user you're running Tomcat as and what effective permissions they will have.

Andrzej Doyle
A: 

I solved the problem. As Andrzej suggested, the problem wasn't in permissions. The filepath was wrong, because i didn't use serverContext.getRealPath() for writing files. I found the solution after seeing this: http://www.velocityreviews.com/forums/t131134-specifying-path-for-file-to-be-read-by-servlet-with-tomcat.html

Tnx.

DixieFlatline