Using struts2 to return xml to the client

View: New views
2 Messages — Rating Filter:   Alert me  

Using struts2 to return xml to the client

by leftkaren :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello, all

 

I want to use struts2.0.14 but I’m a beginner.

I want to return xml to the browser, If I return null in the execute method
of an action, is there any ban consequence? I need some advice.

I just want it this way:

 

In my action:

public String execute() throws Exception{

 

PrintWriter pw = null;

response.setContentType(“text/xml;charset=GBK”);

reponse.setHeader(“Cache-Control”, “no-cache”);

try{

                  pw = response.getWriter();

                  pw.print(“<root><child>Lucy</child></root>”);

} catch (IOException e) {

                  e.printStackTrace();

} finally {

                  pw.close();

                  pw = null;

}

 

return null;

 

}

 

 


Re: Using struts2 to return xml to the client

by Paweł Wielgus :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi karen,
yes, the way You described it, should work without any problems.


Best greetings,
Paweł Wielgus.

2009/11/6 karen <leftkaren@...>:

> Hello, all
>
>
>
> I want to use struts2.0.14 but I’m a beginner.
>
> I want to return xml to the browser, If I return null in the execute method
> of an action, is there any ban consequence? I need some advice.
>
> I just want it this way:
>
>
>
> In my action:
>
> public String execute() throws Exception{
>
>
>
> PrintWriter pw = null;
>
> response.setContentType(“text/xml;charset=GBK”);
>
> reponse.setHeader(“Cache-Control”, “no-cache”);
>
> try{
>
>                  pw = response.getWriter();
>
>                  pw.print(“<root><child>Lucy</child></root>”);
>
> } catch (IOException e) {
>
>                  e.printStackTrace();
>
> } finally {
>
>                  pw.close();
>
>                  pw = null;
>
> }
>
>
>
> return null;
>
>
>
> }
>
>
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@...
For additional commands, e-mail: user-help@...