后台传xml到jsp页面处理
2016-03-23 16:34
483 查看
-------------------------------------------------------
@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>
@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>
相关文章推荐
- ExtJs4 笔记(2) ExtJs对js基本语法扩展支持
- js 禁止后退键
- iOS JavaScriptCore与H5交互时出现异常提示
- KMP算法学习笔记(一)
- js与oc 交互
- javascript一些知识点记录
- JS触发file类型Input的onclick()
- getElementById,getElementsByName,getElementsByTagName简单理解
- JavaScript模态窗口
- js点击显示隐藏
- escapeXml过滤掉特殊字符
- pace.js – 网页自动加载进度条插件
- JavaScript 闭包解析
- javaScript日期对象格式化
- 各种浏览器全屏模式的方法、属性和事件介绍(转)
- 基于javascript实现泡泡大冒险网页版小游戏
- 简单实用的js调试logger组件
- js原生事件系统与坐标系统
- 基于javascript实现句子翻牌网页版小游戏
- JS倒计时网页自动跳转代码