15,000 Jobs Available in:
Java, ASP, C#, PHP, SQL, SAP, MySQL and many more.
- Class Quick -
The moose likes Servlets and the fly likes Serialization Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Serialization Problem" Watch "Serialization Problem" New topic
Author

Serialization Problem

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 706
I have a J2EE web app created in netbeans 6.9,

It has a package 'main' with a class that should write the objects to file.

The class that writes the objects has a main method which can be run to test the objects get written, which they do.

Essentially I have the code,



Which creates the testFile.ser file at the root of the project.

But when I run the web-app locally, the file isn't written.
I'm thinking I need to adjust the path, like "/testFile.ser" or something, but this doesn't work.

Can anyone help? Thanks
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 48842

You have no control over what the "current directory" is within a web app. So using relative file paths is fraught with danger. Use an absolute file path.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 706
Oh I see, thanks, yes this works.

So I guess this applies when I upload project to server, I should use:

www.mywebsite.com/projectName/testFile.ser
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
When you upload, your servlet (or whatever) should write the stream somewhere outside the web application. It avoids accidental deletions on a redeploy, and is the *only* option when deploying a war file.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 706
Hi, so I'm using an absolute path, and it works fine locally, but when I upload to server and run web-app:

HTTP Status 500:

java.security.AccessControlException: access denied (java.io.FilePermission http:/colin-java.co.uk/BankApp/K2GFYZHZP1CH.ser write)

So I tried setting the file permissions on the BankApp folder to allow everything, but it makes no difference.


I believe I have to do something with a policy file, but I don't know where it goes.
Basically I create my war file with netbeans 6.9, upload to server using Tomcat 6, and I get it deployed.

Can anyone help? Thanks
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 2118

You're trying to write to a web address. That's not going to work. You still need the actual disk location.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 706
Thanks, but I don't get it, I donno what that location is
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
http:// is the HTTP protocol. You can't just write arbitrary files to a web app.

The web app should take the uploaded file and write it somewhere known to the web app (we have no way of knowing where that would be on your system) using an absolute path.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 706
Thanks, but I got no idea..

On the server, the top directory is web-root I think.

I just put the path as "BankAppFolder/ABC.ser", where BankAppFolder is in the same directory as the war file.

I donno if it works yet, cause it takes time for them to reload it. Thats why I don't really want to reload it 50 times trying different paths, was hoping someone could point me in the right direction.

Thanks for any help.
Lester Burnham
Rancher

Joined: Oct 14, 2008
Posts: 1337
As Bear said, in web apps you can't use relative paths (Like "BankAppFolder/ABC.ser"), so you need to figure out what the correct absolute path is. If you're not sure what that is, ask the server admin.
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 706
Thanks, I asked them, the path was

/home/colinjava/web-root/BankAppFolder/ABC.ser

and this works, seems hard work writing web-apps, always something wrong or not working, or thats probably just me
 
 
subject: Serialization Problem
 
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture