aspose file tools*
The moose likes Tomcat and the fly likes Read Permission to WEB-INF Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Read Permission to WEB-INF" Watch "Read Permission to WEB-INF" New topic
Author

Read Permission to WEB-INF

Vrunda Joshi
Ranch Hand

Joined: Dec 03, 2001
Posts: 104
Hi all

I am trying to develop a File Upload facility for my website.Because of restrictions from my hosting services I am not able to "write" anything on the server. So I am trying to insert the file into database.For that I need to read the file and then insert it into database.

All this works fine on my local machine.But on my hosting service,it doesn't. I get a exception which is..

java.security.AccessControlException: access denied (java.io.FilePermission "filename" read)

I have just given first line..
So I am not able to read the file itself. How do I solve this problem?

I found out that I can change the permissions through "catalina.policy" but I can't do that in my hosting service.

Is there any other way around.

This is a bit urgent.

Thanks in advance
-Vrunda Joshi

[Bear edit: removed "urgent" from title]
[ July 24, 2006: Message edited by: Bear Bibeault ]

-Vrunda Joshi<br />SCJP,SCWCD,SCBCD(preparing...)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18908
    
    8

In a web application, "uploading a file" does not involve reading any files. It simply involves reading a stream of data from the request. So read from that stream and copy the data directly into the database. I use Apache Commons FileUpload to do this.
Vrunda Joshi
Ranch Hand

Joined: Dec 03, 2001
Posts: 104
Hey Paul,

Thanks for the immediate response. I was waiting well,by reading the file,I didn't mean it.I am giving my code.



Even the uploadFile.length() throws java.security.AccessControlException: access denied

do let me know if I need to change anything, also can you give some code hints plz
thanks
-Vrunda
Murad Iqbal
Ranch Hand

Joined: Dec 09, 2003
Posts: 90
Hi,

Although, a better way to do it is use the apache commons fileupload. You may want to alter your code a bit in order to achieve file upload facility. As far as i can think, the problem wont arise in reading the byte stream from the request or writing it to the db, instead, when you are accessing the file, this is when you will encounter this issue.

So Vrunda, could you please tell us how would you access the client's file?


Cheers,
Murad.
Vrunda Joshi
Ranch Hand

Joined: Dec 03, 2001
Posts: 104
Hi Murad Iqbal,

Thanks for your reply.I really appreciate it.You can see the code which I have written in my earlier post. That is how I am reading a file from client side.From a jsp page which has a "input type=file" I am submitting it to a servlet,and then through that servlet,I am calling a .java prog which is doing the actual file upload to database.

Also,to use apache commons fileupload,what do I need to do?

Thanks a lot,
-Vrunda Joshi
Vrunda Joshi
Ranch Hand

Joined: Dec 03, 2001
Posts: 104
Hi,

Since I am not able to solve my problem,I am thinking of implementation authentication.Which I think might implement security and will help to read and write to/from client and to the database.

Does this sound a good solution? Which type of authentication would be suitable? I am new to this.

Any help is Welcome.
Thanks
-Vrunda
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

I'm really not understanding what's going on. If the file is being uploaded from the client, then why is the database code using FileInputStream to read it? This class would be used to read a disk file on the server -- but you don't have a disk file on the server, you have a stream of bytes from the client. As has already been stated, there should be no reason whatsoever to open any disk files on the server.

Sometimes people new to web app development (and even people not so new) get confused about what happens on the server, and what on the client, and whether a file path refers to a path on the client or on the server -- perhaps this is one of those times?


[Jess in Action][AskingGoodQuestions]
Vrunda Joshi
Ranch Hand

Joined: Dec 03, 2001
Posts: 104
Hey Ernest Friedman-Hill,
Thanks for your reply.I am sorry if I have caused any confusion. I will try to clear how I am working,

1) I am trying to upload a file from client side to database on server.
2) I am doing it with the above code.

I think you are right, and I am confused. Well now the problem is I am getting,

java.security.AccessControlException: access denied java.io.FilePermission C:\Documents and Settings\Mandar\My Documents\Vrunda\abc.txt read)

exception.So I don't know what to do.

I am having a site hosting service with godaddy.

Please let me know what can be done,
Thanks
-Vrunda
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
java.security.AccessControlException: access denied java.io.FilePermission C:\Documents and Settings\Mandar\My Documents\Vrunda\abc.txt read)

I am coming late to this discussion so I may have missed something but that looks like an exception thrown on your client program that has nothing to do with the service. That looks like a windows path and I doubt that godaddy hosting runs on Windows.
Bill
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
I second Ernest - I don't understand what's going on. When uploading a file to a web server, you do not have a file. Why do you even use FileInputStream - there's no possible way it could do something useful. Where is this code you posted supposed to run?


Ping & DNS - my free Android networking tools app
Vrunda Joshi
Ranch Hand

Joined: Dec 03, 2001
Posts: 104
hey Ulf Dittmer & William Brogden,

Thanks for your replies. Looks like I have created a lot of confusion here. Let me explain.

I am working on website which is hosted by (has hosting service)godaddy.We are having Linux based hosting plan.

I am developing a File upload component,so that anybody will be able to uplad file on the site from anywhere when he/she visits the site,I want to insert the file into the database that's with the godaddy's site.For that purpose,I was using FileInputStream,I don't know anyother better/simple way.Please let me know.

I have developed this program on my own and I have been testing it on my local pc,local db which was working fine. I put it on godaddy to test it,and it has stopped working and it's giving me the exception I have mentioned.
So I am really not able to understand what the problem is?One reason I think is,it's restricting the WEB-INF/classes folder from reading client files.

Again that's what I think,
Please bear with the lengthy explaination, I hope I've made myself clear now.
I do apologize for the inconvinience that has caused and I really appreciate your replies.
Thanks
-Vrunda
Sorr
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42635
    
  65
You do not need a client-side file upload component - the browser and a simple HTML page will suffice. For the server-side file upload component, look into Jakarta Commons FileUpload. More than likely it does everything you need done. You will end up with the file contents in a byte array. That you can store in a database, probably as a Blob type. Nowhere is there any File or File[In|Out]putStream involved in any code you need to write. As you have discovered, you are not allowed to use that anyway.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Read Permission to WEB-INF