I have a link on my jsp “Export to CSV”.
On clicking this link what I want to do is
- Send request to action.
- Action populates a A data List
- Result is dispatched to jsp.
- Jsp iterates over data List and generate out put in csv format.
- A download file popups opens with generated CSV file having name “myFile.csv”
I think I am missing something in Struts.xml. I tried
<action name="csvAction" class="demo.csvAction">
<result>csvPage.jsp<result>
</action>
It works well but download popup shows file name “csvAction.go”.
Then I tried
<action name="csvAction" class="demo.csvAction">
<result type="stream">
<param name="location">csvPage.jsp</param>
<param name="contentType">application/csv</param>
<param name="contentDisposition">filename="myFile.csv"</param>
<result>
</action>
But it ignores location attribute and expects an input stream here.
Can anyone guide me?
In that case jsp should also provide the file name by default its giving action name.
for the second method you pass the inputStream and then use this inputstream to create the CSV(which means you prepare the csv from datalist in Struts) and then return it as attachment.
Just for Info : If you create excel then you can use jxl or poi.