Struts2 返回 xml 格式数据
来源:互联网 发布:三星note5绘图软件 编辑:程序博客网 时间:2024/06/05 02:11
方法一: 直接利用ActionSuport的execute方法:
struts.xml中代码,不需要定义 result,
- <action name="OutxmlExecute" class="com.OutxmlExecuteAction" >
- </action>
Action中代码,注意这里execute方法的返回为null,:
- public String execute() throws IOException{
- String outPut = "<persons>";
- outPut += "<person1><name>hanyoud</name><age>25</age></person1>";
- outPut += "<person2><name>张三</name><age>18</age></person2>";
- outPut += "<person3><name>李四</name><age>20</age></person3>";
- outPut += "</persons>";
- //转换编码 否则汉字显示为乱码
- outPut = new String(outPut.getBytes("UTF-8"),"ISO-8859-1");
- HttpServletResponse response = ServletActionContext.getResponse();
- response.setContentType("text/xml ");
- PrintWriter pw = response.getWriter();
- pw.print(outPut);
- System.out.println("-------------------------------");
- return null;
- }
方法二:利用result类型为plaintext返回xml
struts.xml代码,
- <action name="Outxml" method="outxml" class="com.OutxmlAction" >
- <result name="xmlMessage" type="plaintext"></result>
- </action>
Action中代码:
- public void outxml() throws IOException {
- em.out.println("=======================");
- HttpServletResponse response = ServletActionContext.getResponse();
- response.setContentType( "text/xml;charset=utf-8" );
- PrintWriter pw = response.getWriter();
- pw.print( "<persons>" );
- pw.print( "<person1><name>hanyoud</name><age>25</age></person1>" );
- pw.print( "<person2><name>ss</name><age>18</age></person2>" );
- pw.print( "</persons>" );
0 0
- Struts2 返回 xml 格式数据
- Struts2返回XML,JSON格式
- struts2 json格式返回数据
- struts2返回json格式数据
- Struts2如何返回XML数据
- 【转】Struts2返回XML,JSON格式
- Struts2不用插件返回json格式数据
- WebService 返回json格式和返回xml格式的数据
- ajax请求Struts2返回xml数据方法
- XMLHttpRequest处理xml格式的返回数据
- SQL返回XML格式的数据
- 访问页面返回XML格式的数据
- 访问页面返回XML格式的数据
- ajax处理返回的xml格式数据
- 学习笔记--Ajax:XML格式返回数据
- Spring MVC返回XML格式的数据
- Spring MVC返回XML格式的数据
- struts2的action中返回json格式的数据
- 64位Debian-7安装WPS
- android.graphics.Camera 实现简单的3D效果
- OCP-1Z0-053-200题-16题-98
- Servlet
- 强大的jquery绘图开源插件
- Struts2 返回 xml 格式数据
- 值得一看!给中年工程师的忠告
- rails 提示Errno::ENOENT: No such file or directory - /tmp/mysql.sock的解决方法
- LCD驱动(FrameBuffer)实例开发讲解
- 搭建一个自己的博客网站
- javascript 获取系统字体
- vi编辑器的使用
- 飞凌嵌入式OK210开发板手册上的错误集锦及解决方法【持续更新】
- iOS7中UIKit支持的动力行为之UIAttachmentBehavior