struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Li Ying <>
Subject Re: Struts2 - Generate XML in an Action, then direct user to download .xml
Date Wed, 13 Oct 2010 05:02:47 GMT
You can generate your XML dynamically, and then write it to the response stream.
If you set the response headers correctly, the browser should treat
this response as a file downloading.

Code in your action looks like this:

public String execute() {
      String xmlStr = generateXML();

      HttpServletResponse response = ServletActionContext.getResponse();


                        "attachment; filename=" + yourXmlFileName);

      OutputStream out = response.getOutputStream();



      return null;  // this make sure the page not to jump

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message