package com.doumee.core.utils;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServletResponse;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import io.swagger.util.Json;
/**
*
* 功能:详细的功能描述
* 作者:www.doumee.com
* 日期: Dec 14, 2013
* 更新者:
* 日期:
* 更新内容:
*/
public class HtmlUtil {
/**
*
*
* 功能:输出json格式
* 作者:www.doumee.com
* 日期: Dec 14, 2013
* @param response
* @param jsonStr
* @throws Exception
*/
public static void writerJson(HttpServletResponse response,String jsonStr) {
writer(response,jsonStr);
}
public static void writerJson(HttpServletResponse response,Object object){
try {
response.setContentType("application/json");
writer(response,JSONObject.toJSONString(object));
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
*
*
* 功能:输出HTML代码
* 作者:www.doumee.com
* 日期: Dec 14, 2013
* @param response
* @param htmlStr
* @throws Exception
*/
public static void writerHtml(HttpServletResponse response,String htmlStr) {
writer(response,htmlStr);
}
private static void writer(HttpServletResponse response,String str){
try {
StringBuffer result = new StringBuffer();
//设置页面不缓存
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setCharacterEncoding("UTF-8");
PrintWriter out= null;
out = response.getWriter();
out.print(str);
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}