escape html

public static String encodeHTML(String str)
  {
    if ((str == null) || (str.length() == 0))
    {
      return "";
    }
    str = str.replaceAll("&", "&");
    str = str.replaceAll("<", "&lt;");
    str = str.replaceAll(">", "&gt;");
    str = str.replaceAll("\"", "&quot;");
    str = str.replaceAll("'", "&#39;");
    str = str.replaceAll("\\(", "&#40;");
    str = str.replaceAll("\\)", "&#41;");
    str = str.replaceAll("%", "&#37;");
    str = str.replaceAll("\\+", "&#43;");
    str = str.replaceAll("-", "&#45;");

    return str;
  }

你可能感兴趣的:(escape)