zoukankan      html  css  js  c++  java
  • 【开发笔记】- 转义html特殊字符

     1 package com.juihai.util;
     2 
     3 import org.apache.commons.lang.StringUtils;
     4 import org.springframework.web.util.HtmlUtils;
     5 
     6 public class EscapeHtmlUtil {
     7     /**
     8      * 转义html特殊字符
     9      * @param str
    10      * @return
    11      */
    12     public static String escapeHtml(String str) {
    13         str = StringUtils.replace(str, "'", "'");
    14         str = StringUtils.replace(str, """, """);
    15         str = StringUtils.replace(str, "<", "&lt;");
    16         str = StringUtils.replace(str, ">", "&gt;");
    17         str = StringUtils.replace(str, "(", "&#40;");
    18         str = StringUtils.replace(str, "&", "&amp;");
    19         str = StringUtils.replace(str, ")", "&#41;");
    20         str = StringUtils.replace(str, "
    ", "");
    21         str = StringUtils.replace(str, "
    ", "");
    22         str = StringUtils.replace(str, "	", "");
    23         return str;
    24     }
    25     
    26     public static String escapeHtml4Search(String str) {
    27         str = HtmlUtils.htmlEscape(str);
    28         str = StringUtils.replace(str, """, "&quot;");
    29         str = StringUtils.replace(str, "(", "&#40;");
    30         str = StringUtils.replace(str, ")", "&#41;");
    31         str = StringUtils.replace(str, "/", "&#47;");
    32         return str;
    33     }
    34     
    35 }
  • 相关阅读:
    一般图的最大匹配-带花树算法
    Codeforces703D-Mishka and Interesting sum-离线树状数组
    HDU4578-代码一点都不长的线段树
    AOJ.综合训练.2016-12-1
    AOJ.综合训练.2016-12-1
    队列的实现
    队列的实现
    栈的实现
    栈的实现
    贪心算法总结
  • 原文地址:https://www.cnblogs.com/juihai/p/10728349.html
Copyright © 2011-2022 走看看