hi all, I am trying to deploy my file upload servlet on linux. I am creating first checking for the existance of the folder,if it does not exist, I am creating new folder. This whole code works fine on my local machine. I am trying to deploy this code on my linux server,where I am not able to check for existing folder. So I manually created a folder with same name and now I am using that to upload. Still I am getting error as "java.security.AccessControlException: access denied" My folder doesn't have write access as the error shows,but I have manually spcified all "permissions" to all.
can anyone help me solve this problem thanks in advance -Vrunda Joshi
It looks like the user, under which your container is running, doesn't have sufficient permissions to create or write to the directory you've specified.
Thanks for your reply. How would I know under which user the container is running? And is there any way I can change or create specific permissions while creating the directory/file?
What container are you using? What OS? How did you install it? How are you running it?
Vrunda Joshi
Ranch Hand
Joined: Dec 03, 2001
Posts: 104
posted
0
Hey Ben,
Thanks for your instant reply. I appreciate it. Well I have a hosting service thats on Linux,and with that I got a Tomcat server pre-installed, and a default WEB-INF folder only. I just put my servlet class files in it and am now able to run my servlets and JSP pages now.
That is it,do let me know if you need anything more Thanks Vrunda
Vrunda Joshi
Ranch Hand
Joined: Dec 03, 2001
Posts: 104
posted
0
Hi all,
I still haven't solved the problem. I contacted the support team guys and came to know that I can not write to the server since we have hosting servce.
I can write to /tmp folder by referencing it.I am not sure as to what does that mean.There is no such pysical folder.
If anyone has any idea do let me know, it's a bit URGENT
thanks in advance
Vrunda
Carl Trusiak
Sheriff
Joined: Jun 13, 2000
Posts: 3340
posted
0
You do have permission to write to folders under your webapp. You can find the path to these using ServletContext.getRealPath
Write the files to a directory there and you'll be fine.
Hey Carl Trusiak, Thanks for your reply. I tried to do it too. But the problem is, since the webapps is on server I can not write to it. Following is the code..
String strPath = context.getRealPath("//WEB-INF"); File newFile = new File(strPath);
and I got the same error.. "java.security.AccessControlException: access denied (java.io.FilePermission /write )"
As per the support team, I can not write anything to server
Thanks for your reply though
-Vrunda Joshi
Vrunda Joshi
Ranch Hand
Joined: Dec 03, 2001
Posts: 104
posted
0
hi all,
I am still trying to solve the issue. Is there any other work around to this?I need to upload file from client to server.But since I am not able to write on server I don't know how to solve this problem,
Can anybody help me in this matter?
I highly appreciate any help thanks, -Vrunda
Dave Robbins
Ranch Hand
Joined: Sep 16, 2003
Posts: 131
posted
0
in your original post you said you 'manually created a folder" how did you do this if you can't write to the disk?
do you have access to a database on the server? can you save your info there rather than writing it to a file?
Dave
Vrunda Joshi
Ranch Hand
Joined: Dec 03, 2001
Posts: 104
posted
0
hi Dave Robbins,
Thanks for your reply. What I meant by manually creating a folder is, I can create a folder the way we create on our hard drives. But I can not write to that folder nor can I create my own folder programmatically.Through the properties of the folder I made it writable still I could not write to it. As I contacted the support guys, I was told that I can not write anything to the server which is bothering me a lot.
I had not thought of the database option you have suggested. That sounds good. Do you have any idea as to how does that work or what do I have to do?
I have mysql database.Thanks for the suggestion -Vrunda
Dave Robbins
Ranch Hand
Joined: Sep 16, 2003
Posts: 131
posted
0
I'm no expert on this stuff so let's wait and see if somebody who knows what they're talking about will chime in on the details I suspect they'll say the standard way to approach this is to write the file to disk like you tried, then store the path to the file in the database but, of course you have an access problem you're trying to solve I think putting the file itself in the DB is a viable solution, I think you just set the datatype type blob or medium blob depending on the file size, but I've never done this myself I'd be interested to hear from somebody knowledgeable about potential pitfalls of this approach (performance is an issue I expect) In the meantime I'll piddle with it a bit and try to make it work
Dave
Dave Robbins
Ranch Hand
Joined: Sep 16, 2003
Posts: 131
posted
0
this code snippet
will put targetFile in the table "mytable" in column "data" which is of type "blob" I haven't read it back out to make sure it's not mangled but I gotta leave something for you to do the docs for setBinaryStream talks about how to handle large files do you know how to setup your jdbc connection?
Dave
Vrunda Joshi
Ranch Hand
Joined: Dec 03, 2001
Posts: 104
posted
0
Hey Dave Robbins, Thanks for your reply. Sorry I could not reply earlier.I tried hard to write the file on server but still not working.So thought of shifting to the database solution. I tried out a sample code that I got from net and some part that you gave.Thanks for leaving some part for me to do it made me fight I initially got some problem with driver etc. but my sample prog on my local pc just worked fine.At least it's showing my file's name in the table. Here I am having one "more" problem it seems that request.getParameter doesn't work with the "multipart-form/data" as I found on some forums.I am getting null with it. I have a jsp page where I have input type "file". I need to pass the selected file to the uploading class,to save to db. for testing,I hardcoded the path,and it worked. Is there any other way to it?
Check the documentation for the upload library you're using. They all have a way to retrieve form parameters.
Vrunda Joshi
Ranch Hand
Joined: Dec 03, 2001
Posts: 104
posted
0
Hey Ben Souther, Thanks for the reply. I went through all the documentation and here's how I did it.
I set action of the JSP page to same page.then in onsubmit,I changed it to the servlet I wanted, I also set the form "enctype" and set the parameters and submitted the form.Now I got the values I wanted in the servlet.Then I inserted the file value into the Database which is working fine. I have used Blob for file contents
Now I want to retrive the file which can be a doc or word file. I want to open the file,when I click on the href of the name of the file.I have retrieved the name, and I have created a RandomAccessFile from the blob field.I just want to open the file as would open when we click open on any attachment etc...