java로 html태그가 포함된 문자열 치환

import org.apache.commons.lang3.StringEscapeUtils;

public String escapeHtml(String log) {
    if (log != null && log != "") {
        log = StringEscapeUtils.escapeHtml4(log);  // html의 특수문자 치환
        log = "<pre>" + log + "</pre>";  // <pre>는 줄바꿈이나 공백 적용한 상태로 보여줌
    }
    return log;
}

Tags:

Categories:

Updated:

Leave a comment