aspose file tools*
The moose likes JSP and the fly likes Creating file on server - java.io.FilePermission - access denied Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Creating file on server - java.io.FilePermission - access denied" Watch "Creating file on server - java.io.FilePermission - access denied" New topic
Author

Creating file on server - java.io.FilePermission - access denied

Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
Hi,

I'm really not sure whether this question belongs to this forum or not.. but since I'm working on JSPs.. I'm posting it here...

I have a JSP which is trying to create a file on the server..



The above worked fine in my local computer and created a file in application directory.. But thrown below exception when I uploaded it to server (java web hosting provided by godaddy.com)



I thought the problem was with file/directory permissions.. I tried changing permissions to 777 but nothing worked... Then I wrote PHP file which does the same..


The above php code worked fine and created file on server..

with this I found that the problem is with my java code.. After doing little bit of research (for two days) I found that I need to have a .java.policy file to give FilePermission access (write).. But I could not figure of how..

I have a kept a file .java.policy with below content in my web app directory.



Also updated jsp code to use this java policy file.. (by adding it to env variables)



But still I'm getting same exception....

Can you please tell me how to resolve this issue..

My Limitation is I dont have access to any file out side my web application in the server..

Hope I'm clear with my problem.. Please suggest me the solution..

Thanks in advance..


SCJP 5.0 : 88% My Story, SCWCD 1.4 : 94% My Story
kishoreballa.com
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Is Tomcat (assuming it's Tomcat) running under a security policy?
Is it running under a user with write permissions to that directory?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
Originally posted by Ben Souther:
Is Tomcat (assuming it's Tomcat) running under a security policy?
Is it running under a user with write permissions to that directory?


Yes. It is Tomcat..

And I think its running under security policy (I feel thats the reason for exception)..

I'm not sure whether tomcat is running under a user with write permissions... In godaddy website.. its mentioned that "All of our Java-enabled hosting accounts are running in a shared JVM."... and only my user account has write permissions to that directory..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If this is a hosted server, you would probably need to check with the hosting company to see if, how, and were you are allowed to write files.
Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
Originally posted by Ben Souther:
If this is a hosted server, you would probably need to check with the hosting company to see if, how, and were you are allowed to write files.


Will write them now...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
This is odd, because usually the code should have write access to all files/directories in your web app (which I'm guessing is the .../kishoreballa/... directory). But the policy setup of the server may not be correct, as Ben says.

The way you're trying to set up the security manager won't work, by the way. Besides that it doesn't work like that, you most likely won't have permissions to set up security managers in your web app.
[ September 24, 2006: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
This is the what I've got from my hosting website

***************************************************************

Dear kishore balla,

Thank you for contacting customer support.

Please note that Java can only read/write to the /tmp directory on our shared hosting environment and this is the reason why you are getting the error that you. Please let us know if you have any further issues or concerns.

Best regards,

Advanced Hosting Support

***************************************************************
Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
Originally posted by Ulf Dittmer:
This is odd, because usually the code should have write access to all files/directories in your web app (which I'm guessing is the .../kishoreballa/... directory). But the policy setup of the server may not be correct, as Ben says.


YOu guys are correct... They said using java we can write only to /tmp directory.. Can you guys please suggest me something.. which I can ask my hosting provider to change/update so that write access will be given...

Originally posted by Ulf Dittmer:

The way you're trying to set up the security manager won't work, by the way. Besides that it doesn't work like that, you most likely won't have permissions to set up security managers in your web app.



So.. securiy managers are for whole server.. may be I can atleast ask them to update their config files so that I will get access to my dir.. (please suggest me how)..
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Couple thoughts.

Do you need to write the file to disk or is this something that could be stored in a database?

You could remind them that the PHP side of things can write the file (of course they might just disable that capability in PHP).

Does the file need to stay up there for a long time?
If not, maybe the /tmp directory would be sufficient for you.

If you've already done this in PHP, you might want to just use the PHP script for that one feature.


There are plenty of other hosting companies out there.
Kishore Balla
Ranch Hand

Joined: Jun 08, 2005
Posts: 165
Actually my actual requirement was not to create a file on server.. But to write a servlet/jsp which allows user to upload the file to server from browser using http...

I have used package com.orielly.servlet for this.. and script worked great in my local computer.. Things gone bad when I uploaded my scripts to Godaddy server and it took one 5 days for me to figure out the cause..

Now I'm trying to write a PHP file instead of the jsp for this uploading stuff.
 
Consider Paul's rocket mass heater.
 
subject: Creating file on server - java.io.FilePermission - access denied