output Script from HttpServletResponse - Java Servlet JSP

Java examples for Servlet JSP:Servlet

Description

output Script from HttpServletResponse

Demo Code


import org.apache.log4j.Logger;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Set;

public class Main{
    public static void outScript(HttpServletResponse response, String json) {
        response.setHeader("Cache-Control", "no-cache");
        response.setContentType("application/javascript;charset=UTF-8");
        try {/*from w w  w  .  j  av  a 2s  .c o  m*/
            response.getWriter().write(json);
            response.getWriter().flush();
            response.getWriter().close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related Tutorials