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
Joined: Mar 05, 2002
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!
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.
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
Jeroen T Wenting
Joined: Apr 21, 2006
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.
Joined: Mar 05, 2002
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 ]