用struts2给android客户端发送xml数据

来源:互联网 发布:武汉学编程多久 编辑:程序博客网 时间:2024/06/07 11:10

一、严格按照xml文件的格式书写,防止struts标签影响到xml的格式:

<?xml version="1.0" encoding="UTF-8"?><%@ page language="java" contentType="text/xml; charset=UTF-8" pageEncoding="UTF-8"%><%@taglib uri="/struts-tags" prefix="s"%>

<videos><s:iterator value="#request.videos" id="video" >
<video id="<s:property value="id"/>">
<name><s:property value="name"></s:property></name>
<time><s:property value="time"></s:property></time>    
</video></s:iterator>

</videos>


注意:1.<?xml version="1.0" encoding="UTF-8"?>必须是文件的开头一句,前面不要有空格,是xml文件的规定。

2.注意文档的格式,<videos><s:iterator value="#request.videos" id="video" >这两段间不要换行,防止以后解析出现不必要的麻烦

二、下面是浏览器看到的效果:

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<videos>
<video id="59">
<name>情歌</name>
<time>2:30</time>
</video>
<video id="19">
<name>老男孩</name>
<time>2:50</time>
</video>
<video id="39">
<name>那些年</name>
<time>3:30</time>
</video>
</videos>

原创粉丝点击