• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Serialization Problem

 
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but I don't get it, I donno what that location is
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 1337
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 750
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic