// Path: src/main/java/com/tkhoon/framework/Constant.java
// public interface Constant {
// 
//     String DEFAULT_CHARSET = "UTF-8";
// 
//     String APP_HOME_PAGE = "app.home_page";
//     String APP_JSP_PATH = "app.jsp_path";
//     String APP_WWW_PATH = "app.www_path";
// 
//     String SERVLET_DEFAULT = "default";
//     String SERVLET_JSP = "jsp";
//     String SERVLET_UPLOAD = "upload";
// 
//     String REQUEST_FAVICON = "/favicon.ico";
//     String REQUEST_UPLOAD = "/upload.do";
// 
//     String UPLOAD_BASE_PATH = "upload/";
//     String UPLOAD_PATH_NAME = "path";
//     String UPLOAD_INPUT_NAME = "file";
//     String UPLOAD_FILE_NAME = "file_name";
//     String UPLOAD_FILE_TYPE = "file_type";
//     String UPLOAD_FILE_SIZE = "file_size";
// 
//     String PLUGIN_PACKAGE = "com.tkhoon.plugin";
// }


import com.tkhoon.framework.Constant;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import org.apache.log4j.Logger;
package com.tkhoon.framework.util;


public class WebUtil {

    private static final Logger logger = Logger.getLogger(WebUtil.class);

    // 将数据以纯文本格式写入响应中
    public static void writeText(HttpServletResponse response, Object data) {
        try {
            // 设置响应头
            response.setContentType("text/plain"); // 指定内容类型为纯文本格式
            response.setCharacterEncoding(Constant.DEFAULT_CHARSET); // 防止中文乱码

            // 向响应中写入数据
            PrintWriter writer = response.getWriter();
            writer.write(data + ""); // 转为字符串
        } catch (Exception e) {
            logger.error("在响应中写数据出错！", e);
            throw new RuntimeException(e);
        }
    }

    // 将数据以 JSON 格式写入响应中
    public static void writeJSON(HttpServletResponse response, Object data) {
        try {
            // 设置响应头
            response.setContentType("application/json"); // 指定内容类型为 JSON 格式
            response.setCharacterEncoding(Constant.DEFAULT_CHARSET); // 防止中文乱码

            // 向响应中写入数据
            PrintWriter writer = response.getWriter();
            writer.write(JSONUtil.toJSON(data)); // 转为 JSON 字符串
        } catch (Exception e) {
            logger.error("在响应中写数据出错！", e);
            throw new RuntimeException(e);
        }
    }

    // 将数据以 HTML 格式写入响应中（在 JS 中获取的是 JSON 字符串，而不是 JSON 对象）
    public static void writeHTML(HttpServletResponse response, Object data) {
        try {
            // 设置响应头
            response.setContentType("text/html"); // 指定内容类型为 HTML 格式
            response.setCharacterEncoding(Constant.DEFAULT_CHARSET); // 防止中文乱码

            // 向响应中写入数据
// Path: src/main/java/com/tkhoon/framework/Constant.java
// public interface Constant {
// 
//     String DEFAULT_CHARSET = "UTF-8";
// 
//     String APP_HOME_PAGE = "app.home_page";
//     String APP_JSP_PATH = "app.jsp_path";
//     String APP_WWW_PATH = "app.www_path";
// 
//     String SERVLET_DEFAULT = "default";
//     String SERVLET_JSP = "jsp";
//     String SERVLET_UPLOAD = "upload";
// 
//     String REQUEST_FAVICON = "/favicon.ico";
//     String REQUEST_UPLOAD = "/upload.do";
// 
//     String UPLOAD_BASE_PATH = "upload/";
//     String UPLOAD_PATH_NAME = "path";
//     String UPLOAD_INPUT_NAME = "file";
//     String UPLOAD_FILE_NAME = "file_name";
//     String UPLOAD_FILE_TYPE = "file_type";
//     String UPLOAD_FILE_SIZE = "file_size";
// 
//     String PLUGIN_PACKAGE = "com.tkhoon.plugin";
// }


// Path: src/main/java/com/tkhoon/framework/util/WebUtil.java
import com.tkhoon.framework.Constant;
import java.io.PrintWriter;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import org.apache.log4j.Logger;

package com.tkhoon.framework.util;


public class WebUtil {

    private static final Logger logger = Logger.getLogger(WebUtil.class);

    // 将数据以纯文本格式写入响应中
    public static void writeText(HttpServletResponse response, Object data) {
        try {
            // 设置响应头
            response.setContentType("text/plain"); // 指定内容类型为纯文本格式
            response.setCharacterEncoding(Constant.DEFAULT_CHARSET); // 防止中文乱码

            // 向响应中写入数据
            PrintWriter writer = response.getWriter();
            writer.write(data + ""); // 转为字符串
        } catch (Exception e) {
            logger.error("在响应中写数据出错！", e);
            throw new RuntimeException(e);
        }
    }

    // 将数据以 JSON 格式写入响应中
    public static void writeJSON(HttpServletResponse response, Object data) {
        try {
            // 设置响应头
            response.setContentType("application/json"); // 指定内容类型为 JSON 格式
            response.setCharacterEncoding(Constant.DEFAULT_CHARSET); // 防止中文乱码

            // 向响应中写入数据
            PrintWriter writer = response.getWriter();
            writer.write(JSONUtil.toJSON(data)); // 转为 JSON 字符串
        } catch (Exception e) {
            logger.error("在响应中写数据出错！", e);
            throw new RuntimeException(e);
        }
    }

    // 将数据以 HTML 格式写入响应中（在 JS 中获取的是 JSON 字符串，而不是 JSON 对象）
    public static void writeHTML(HttpServletResponse response, Object data) {
        try {
            // 设置响应头
            response.setContentType("text/html"); // 指定内容类型为 HTML 格式
            response.setCharacterEncoding(Constant.DEFAULT_CHARSET); // 防止中文乱码

            // 向响应中写入数据
            PrintWriter writer = response.getWriter();