Below is the code that does that.
The above code creates the file xyz.xml and send it to client to download. But when the client requests for the file, it also creates the file in the application directory. Which I do not want. How to avoid that?
Bear Bibeault wrote:
trupti nigam wrote:The above code creates the file xyz.xml
I see no such code.
It's also a really bad practice to pass a response around, but before we address that we need to know what you are really doing. The code you posted and the description of what it does do not match.
The code creates the file with the "fileName" that is passed to the method.
This is what I do.
1. Client can request a file for different products by passing the product name via the URL
2. Server will get the product Name, build the xml response and create file.
3. Send it over the servletOutPutStream. The End client will be able to get the file in fileName.xml format. The code is working fine. But it also drops the same file on the server box where the app runs. I want to avoid that.
Paul Clapham wrote:It's possible that the code underlying "secResponse.toString()" writes a file to the current working directory on the server as a side-effect. Or it's possible that some other part of creating that SecurityListImpl object does that. But in any case it should be obvious that nobody here can see the code which does that. It's going to be up to you to look through the source code for SecurityListImpl -- or whatever class is actually passed to that method -- to find that code.
When I debugged the code the secResponse.toString() line dumps the file on the box. The creation of SecurityListImpl object has nothing to do with this file. When I create this object, I just assign the value to it.
How can I avoid creation of file during secResponse.toString()?
Bear Bibeault wrote:How can we say when you're keeping the important parts of the code a secret?
Generally, rather than stream the XML to a file, stream it to the response output stream. There's rarely a need to create an intermediate disk file just to stream something as a response.
What part of code you would like to see. I shared the code that is being used to actually create the file and send it over HTTPResponse.
Also I am streming the xml to the response output stream.
The requirement is such that, when the end client requests a product details the server should be able to send it to end client in the form of xml file.