0

Problem with write file in servlet deployed on Tomcat

 2 years ago
source link: https://www.codesd.com/item/problem-with-write-file-in-servlet-deployed-on-tomcat.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Problem with write file in servlet deployed on Tomcat

advertisements

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";
    };


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.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK