aspose file tools
The moose likes Java in General and the fly likes to save a file dynamically Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "to save a file dynamically " Watch "to save a file dynamically " New topic
Author

to save a file dynamically

sreedhar
Greenhorn

Joined: May 02, 2006
Posts: 20
Hi All,

my requirement is to save the file dynamically into the local system of the user who ever runs the servlet. iam able to do it with in my local environment with the following code


String p = System.getProperty("user.home");
String C = p.substring(0,3);
File outputFile = new File(C+"Coo_"+ strDate_MMDDYY+".xls");
FileOutputStream out = new FileOutputStream(outputFile);


but its not working when i promote the code to Test environment and try as user please can any one let me know the defect in my code or Any other approach
Thanks in Advance
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
First of all! You are not trying to save a file in the user home directory!
You are requesting the home directory and trying to parse out the drive where the home directory is located.


Second: My question to you is: Are you trying to save a file on the filesystem of the server? Because this is what you are doing! You are asking the home directory of the user who is running the server. In a servlet you are not able to write files on the client's filesystem and I think that this is what you want to do.

Of course this works in your development environment because the server and client are located on the same system.

Tell me if I am wrong! Maybe you should explain a little more about what you are trying to do exactly and then we can help you more!
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12911
    
    3

...but its not working...

What does "it's not working" mean - do you get an exception, or does it appear to do nothing at all?

What is the value of the system property "user.home" on the test system? Add some log statements (maybe just simple System.out.println(...) statements) to your code to find out what's happening when you run it on the test system.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
sreedhar
Greenhorn

Joined: May 02, 2006
Posts: 20
Hi Manuel,

thanks for your reply. You are right my requirement is to save the file inyo client's file system with in as servlet.My code was working fine as you said the clent and server are on the same system.please can you guide me in writing code to store the file into the client's filesystem

thanks
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Short answer: you can't.
Long answer: you can't.

There's nothing more to it, the only ways to get a file to the client from the server are to either save it on the server somewhere in the web application and have the client click a link to download it or to stream it from the server and have the client save it from his browser.

If the server could write directly to the client the security implications would be dramatic.
Everyone on the internet would be able to write to every other computer on the internet without any restrictions. I think you'll see how that is completely unacceptable.


42
Manuel Moons
Ranch Hand

Joined: Mar 05, 2002
Posts: 229
I have to agree with Jeroen on this one.

But... If you really want to save stuff on the clients filesytem (using a thin client= a browser) you will have to start working with Applets or ActiveX controls that use certificates for security issues. Be aware though that this is a bit more complex than writing a simple servlet.

You can follow the tutorial here for more information about this.
[ September 06, 2006: Message edited by: Manuel Moons ]
 
I agree. Here's the link: http://jrebel.com/download
 
subject: to save a file dynamically
 
Similar Threads
Replacing a string in a byte stream
How to delete a file which was created in server after redirecting it to clientside.
to save a file dynamically
Hi All
Image transfer through sockets