博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struts返回xml数据例子
阅读量:2176 次
发布时间:2019-05-01

本文共 805 字,大约阅读时间需要 2 分钟。

 

 //返回xml数据
 public void responseOut() throws Exception
 {
  StringBuilder sb = new StringBuilder();
  sb.append("<?xml version=/"1.0/" encoding=/"UTF-8/" ?>");
  sb.append("<users>");
  sb.append("<user id=/"50/">");
  sb.append("<userName>abc</userName>");
  sb.append("</user>");
  sb.append("<user id=/"50/">");
  sb.append("<userName>eee</userName>");
  sb.append("</user>");
  sb.append("</users>");
  
  //得到response
  HttpServletResponse response = ServletActionContext.getResponse();
  HttpServletRequest request=ServletActionContext.getRequest();
  request.setCharacterEncoding("UTF-8");
  //设置编码    
  //response.setCharacterEncoding("UTF-8");
  response.setContentType("text/xml;charset=utf-8");  
  response.setHeader("Cache-Control", "no-cache");
  PrintWriter out = response.getWriter();   
  out.write(sb.toString());   
  out.flush();
  out.close();

 }

转载地址:http://yofkb.baihongyu.com/

你可能感兴趣的文章
【LEETCODE】155-Min Stack
查看>>
【LEETCODE】20-Valid Parentheses
查看>>
【LEETCODE】290-Word Pattern
查看>>
【LEETCODE】36-Valid Sudoku
查看>>
【LEETCODE】205-Isomorphic Strings
查看>>
【LEETCODE】204-Count Primes
查看>>
【LEETCODE】228-Summary Ranges
查看>>
【LEETCODE】27-Remove Element
查看>>
【LEETCODE】66-Plus One
查看>>
【LEETCODE】26-Remove Duplicates from Sorted Array
查看>>
【LEETCODE】118-Pascal's Triangle
查看>>
【LEETCODE】119-Pascal's Triangle II
查看>>
【LEETCODE】88-Merge Sorted Array
查看>>
【LEETCODE】19-Remove Nth Node From End of List
查看>>
【LEETCODE】125-Valid Palindrome
查看>>
【LEETCODE】28-Implement strStr()
查看>>
【LEETCODE】6-ZigZag Conversion
查看>>
【LEETCODE】8-String to Integer (atoi)
查看>>
【LEETCODE】14-Longest Common Prefix
查看>>
【LEETCODE】38-Count and Say
查看>>