Newton, Ying, Yang,

Works like a charm. Thank you very much.

gove...@students.kennesaw.edu


On Wed, Oct 13, 2010 at 2:24 AM, Steven Yang <kenshin...@gmail.com> wrote:

> Hi Overby
>
> Result is indeed your choice to go.
> in general you should avoid any direct use of the Servlet stuff in your
> Actions.
>
> you should prepare your data in your action or "execute" then determine
> what
> data type you want to return then return the proper "result" string
> then let your Result format the data to what you ie. XML or JSON or even
> plain text
>
> this way your Action wont be view-dependent
> you can dig into struts' source to find many usable examples on how to do
> things in Result
>
>
> On Wed, Oct 13, 2010 at 2:05 PM, Grant Overby <
> gove...@students.kennesaw.edu
> > wrote:
>
> > After some googling; I'm looking at the Result interface.
> >
> > Would it be proper for the action to set a property, and use this custom
> > Result to read that property from ValueStack and write it to (with
> XStream
> > for isntance) ServletActionContext.getResponse().getOutputStream() ?
> >
> > So Results exist for doing this for XML and/or JSON? It seems like it
> would
> > be re-occurring situation, espectially with ajax?
> >
> > I'm just getting into Struts2; I'm looking to see if I'm doing things as
> > they ought to be done. Best practices, etc.
> >
> >
> > gove...@students.kennesaw.edu
> >
> >
> >
> > On Wed, Oct 13, 2010 at 1:02 AM, Li Ying <liying.cn.2...@gmail.com>
> wrote:
> >
> > > 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();
> > >
> > >      response.setContentType("text/xml");
> > >
> > >      response.setHeader("Content-Disposition",
> > >                        "attachment; filename=" + yourXmlFileName);
> > >
> > >      OutputStream out = response.getOutputStream();
> > >
> > >      out.write(xmlStr.getBytes("UTF-8"));
> > >
> > >      out.close();
> > >
> > >      return null;  // this make sure the page not to jump
> > > }
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
> > > For additional commands, e-mail: user-h...@struts.apache.org
> > >
> > >
> >
>

Reply via email to