利用Spring中的HtmlUtils.htmlEscape(input)过滤html

  fatherModule.setModuelName(HtmlUtils.htmlEscape(fatherModule.getModuelName()));
        log.info(HtmlUtils.htmlEscape(fatherModule.getModuelName()));
        log.info(fatherModule);
        String s = HtmlUtils.htmlEscape("<div>hello world</div><p>&nbsp;</p>");  
        log.info(s); 
        String s2 = HtmlUtils.htmlUnescape(s);  
        log.info(s2);   
        adminIndexService.saveFatherModule(fatherModule);
        return "redirect:"+ActionURL.ADMIN_INDEX;

运行结果

2016-01-30 23:02:33 86 INFO AdminIndexAction - &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;123sadfa&amp;lt;/span&amp;gt;
2016-01-30 23:02:33 87 INFO AdminIndexAction - FatherModule [id=null, moduelName=&lt;span style=&quot;color:red&quot;&gt;123sadfa&lt;/span&gt;, sort=0]
2016-01-30 23:02:33 89 INFO AdminIndexAction - &lt;div&gt;hello world&lt;/div&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;
2016-01-30 23:02:33 91 INFO AdminIndexAction - <div>hello world</div><p>&nbsp;</p>

这个还需优化,这个应该只在哪些具有输入的地方进行过滤,这个怎么实现呢?

转载于:https://www.cnblogs.com/rocky-AGE-24/p/5170277.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值