본문 바로가기

Programming/Java

[Servlet] HttpServletResponse를 통한 Javascript 수행


import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;

public class CommonUtil {
	
	public static void setResponseMessage(HttpServletResponse response, String msg) {
		setResponseHtmlMessageScript(response, null, msg, null);
	}
	
	public static void setResponseScript(HttpServletResponse response, String script) {
		setResponseHtmlMessageScript(response, null, null, script);
	}
	
	public static void setResponseMessageScript(HttpServletResponse response, String msg, String script) {
		setResponseHtmlMessageScript(response, null, msg, script);
	}
	public static void setResponseHtmlMessageScript(HttpServletResponse response, String html, String msg, String script) {
		response.setContentType("text/html; charset=UTF-8");
		response.setHeader("Content-Type", "text/html; charset=utf-8");
		
		try {
			ServletOutputStream out = response.getOutputStream();
			out.print("");
			if ( html != null && !"".equals(html.trim())) {
				out.print(new String(html.getBytes("utf-8"), "ISO_8859_1"));
			}
			out.print("");
			out.print("");
			out.flush();
		} catch ( Exception e ) {
			System.out.println(e);
		}
	}
}

'Programming > Java' 카테고리의 다른 글

[Secret] AES128 암/복호화  (0) 2012.08.14
[Servlet] WAS 구동시 메모리 로드(ServletContextListener)  (0) 2011.12.05
[Beginner] Properties Util  (0) 2011.08.18
[Servlet] EncodingFilter  (0) 2010.03.14
[Server]Server Thread Socket  (0) 2010.03.08