后台传xml到jsp页面处理

来源:互联网 发布:centos编译安装php7.0 编辑:程序博客网 时间:2024/05/17 07:03

-------------------------------------------------------

@RequestMapping(value="test")

public void test(HttpServletRequest request,HttpServletResponse response) throws IOException{
ServletOutputStream out = response.getOutputStream();
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
String s="<?xml version=\'1.0\' encoding=\'UTF-8\'?><root><name>test1</name><age>23</age></root>";
out.write(s.getBytes("utf-8"));
out.flush();
out.close();

}

-------------------------------------------------

<script type="text/javascript">
  $.ajax({
url: basePath+"ssjk_jqryk/test.hs",
dataType: 'xml',
type: 'GET',
timeout: 2000,
error: function(xml)
{
alert("加载XML 文件出错!");
},
success: function(xml)
{
console.info(xml.getElementsByTagName("name")[0].childNodes[0].nodeValue )
}
});


  </script>

0 0
原创粉丝点击