Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to return a file from an Action?


I'd like to have WebWork action return a file. Here's my atlassian.xml:

<action name="export" class="com.playsql.requirement.RequirementAction" method="export">
                <result name="download" type="stream">inputStream</result>

Here's my action:

public String export() {
        try {
            File file = File.createTempFile("export-", ".csv");
            FileUtils.writeStringToFile(file, "bleblebleleheldbelhebelbelbele");
            inputStream = new FileInputStream(file);
            return "download";
        } catch (IOException e) {
            return "error";

However, the browser just shows it, it doesn't download it and doesn't give it a name.

Using this question, I have tried:

<result name="download1" type="stream">
    <param name="contentType">text/html</param>
    <param name="inputName">inputStream</param>
    <param name="contentDisposition">filename=document.csv</param>

but I get this exception, which means WebWork doesn't detect that the contents of the <result> element isn't just text and it tries to parse it as if it were the location.

	at java.util.regex.Matcher.getTextLength(
	at java.util.regex.Matcher.reset(
	at java.util.regex.Matcher.&lt;init&gt;(
	at java.util.regex.Pattern.matcher(
	at com.opensymphony.xwork.util.TextParseUtil.translateVariables(
	at com.opensymphony.webwork.dispatcher.WebWorkResultSupport.execute(
	at com.opensymphony.xwork.DefaultActionInvocation.executeResult(

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted

Note: The other example won't work in IE, because it won't give it the right name. Instead:

public class RequirementAction extends AbstractSpaceAction implements ServletResponseAware {
private HttpServletResponse response;
    public void setServletResponse(HttpServletResponse httpServletResponse) {
        this.response = httpServletResponse;

            response.setHeader("Content-Disposition", "attachment; filename=" + "\"requirement-export.csv\"");
            response.setHeader("Cache-Control", "max-age=0");
            response.setHeader("Pragma", "");

            OutputStream out = response.getOutputStream();
            IOUtils.copy(inputStream, out);

Atlassian Answers is an awesome rubber duck in the sense it helps the community too!

&lt;action name="export" class="com.playsql.requirement.RequirementAction" method="export"&gt;
    &lt;result name="download" type="stream"&gt;
        &lt;param name="contentType"&gt;text/csv&lt;/param&gt;
        &lt;param name="location"&gt;inputStream&lt;/param&gt; &lt;!-- Here's where I was mistaken --&gt;
        &lt;param name="contentDisposition"&gt;attachment; filename=requirement-export.csv&lt;/param&gt;
    &lt;result name="error" type="velocity"&gt;/error.vm&lt;/result&gt;

Hi Adrein,


The content disposition header is not at all reflecting in user's downloaded file.. Did it work for you?

Here is my configuration:

&lt;result name="download" type="stream"&gt;
                    &lt;param name="contentType"&gt;application/vnd.openxmlformats-officedocument.wordprocessingml.document&lt;/param&gt;
                    &lt;param name="contentDisposition"&gt;attachment; filename=test.docx.html&lt;/param&gt;
                    &lt;param name="inputName"&gt;inputStream&lt;/param&gt;
Community showcase
Published in Confluence

Wouldn't it be nice to have this Jira-Confluence integration?

...ossibility became true in a not too far future, project/space access would be left in the hands of all team members. Don't get me wrong: I'd love it! However, it would also be nice to have a way in which j...

59 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you