json对象 post到页面

来源:互联网 发布:大数据运维工程师 编辑:程序博客网 时间:2024/05/01 12:29

 /**
 * @author wanghua
 * TODO向页面传递json对象
 * Nov 2, 2009 5:25:39 PM
 */
public class MessageUtils {
  public static void outputJSONResult(String result, HttpServletResponse response) {  
         try {  
             response.setHeader("ContentType", "text/json");  
             response.setCharacterEncoding("utf-8");  
             PrintWriter pw = response.getWriter();  
             pw.write(result);  
             pw.flush();  
             pw.close();  
         } catch (IOException e) {  
             e.printStackTrace();  
         }  
     }  
       
     public static void outputXMLResult(String result, HttpServletResponse response) {  
         try {  
             response.setHeader("ContentType", "xml");  
             response.setCharacterEncoding("utf-8");  
             PrintWriter pw = response.getWriter();  
             pw.write(result);  
             pw.flush();  
             pw.close();  
  
         } catch (IOException e) {  
             e.printStackTrace();  
         }  
     }  
}

原创粉丝点击