All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.aifaq.commons.lang.ResponseUtil Maven / Gradle / Ivy

There is a newer version: 2.0.3
Show newest version
package me.aifaq.commons.lang;

import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author Wang Wei [[email protected]]
 * @since 17:32 2017/9/29
 */
public class ResponseUtil {
    public static void writeJson(HttpServletResponse response, String str) throws IOException {
        response.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString());

        try (PrintWriter writer = response.getWriter()) {
            writer.write(str);
            writer.flush();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy