使用Apache commons-lang的StringUtils来增强Java字符串处理功能。
StringEscapeUtils一个方便做转义的工具类,主要是为了防止sql注入,xss注入攻击的功能。
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.struts2.ServletActionContext;
public class HtmlUtil {
public static String htmlReplace(String str){
str = StringEscapeUtils.escapeHtml(str);
return str;
}
}