MrShi
2025-09-10 1ff2f63ddc05988ed7d698ef93a905659365446f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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;
 
 
/**
 * <br>
 * <b>功能:</b>详细的功能描述<br>
 * <b>作者:</b>www.doumee.com<br>
 * <b>日期:</b> Dec 14, 2013 <br>
 * <b>更新者:</b><br>
 * <b>日期:</b> <br>
 * <b>更新内容:</b><br>
 */
public class HtmlUtil {
    
    /**
     * 
     * <br>
     * <b>功能:</b>输出json格式<br>
     * <b>作者:</b>www.doumee.com<br>
     * <b>日期:</b> Dec 14, 2013 <br>
     * @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();
            }
    }
    
    /**
     * 
     * <br>
     * <b>功能:</b>输出HTML代码<br>
     * <b>作者:</b>www.doumee.com<br>
     * <b>日期:</b> Dec 14, 2013 <br>
     * @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();
        }
    } 
}