hi all i am displaying certain content to the user(say result.jsp). And in that page there is option for the user to download those contents. My question is how we can get the teh download dialog box, where user will have option to choose the file name. The file format is fixed.
And also i need to retain the result page (result.jsp ).
i am trying to acheive above requirements using LookupDispatchAction servlet.
It may be sufficient just to provide a link with the name of the file. If the file suffix is something other than a common Internet file type(e.g. html, jpg, gif) the browser will generally produce a prompt asking the user what to do with the file.
If you need more control over the download than this, you will have to create an action that will read the file and then output it to the Output stream of the HttpServletResponse object.
Hi The data which i am sending to the client is byte array. To make the client save the data i am doing the following
1) Create a Temp file. (Donno where it will got created.) 2) set the response content type. 3) Pass the created temp file as attachment to the client. which he will save to his local disk.
is there any better way to pass the content to save directly to the file the client specifies, instead of creating the temp file and sending it as attachment.
If possible give me the link where i refer for my requirement.
Joined: Feb 15, 2005
You don't need to write a temporary file. You can just write your Byte array directly to the response. There is an example of how to do this in the struts-examples.war file that comes with the Struts download.
Examine the source code for org.apache.struts.webapp.exercise.ImageAction and you'll see how to do it.
Joined: Mar 01, 2005
hi i went through the example you mentioned. when i tried to reuse the code, i am getting the inputstream as null. i pasted my code snippet below.
I am having a XML file as byte array, which i display to user by converting to string object. User had the option to download that xml file. so i Created the xml String object and pass it to the getResouceAsStream but it returns null. i donno why. but the below code snippet prints the whole xml file as it is.
But when i pass the new string()... to get resouce stream, input stream object is returned as null.
Joined: Feb 15, 2005
In the example, they had to read a file, turn it into an InputStream, and then turn the InputStream into a Byte array. Your situation is much simpler. You've already got a Byte array. If arryByteXmlPayLoad is a Byte array, you don't need to turn it into an InputStream. Just write the Byte array directly to the OutputStream with no looping like this:
You will also want to set the content type and declare it as an attachment like this: