html解析

今天在写公司后台管理系统,调用程序接口发现,返回值是php

<p><img src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444271696.png" _src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444271696.png"/></p><p><img src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444425034.png" _src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444425034.png"/></p><p><img src="wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444571207.png" _src="https://wis3dom.baidu.com/Public/static/um/php/../../../upfile/20170214/14870444571207.png"/></p><p><br/></p>

结果界面不显示,还不理解这是啥,原来是转义,借助php函数htmlspecialchars_decode() 经粗略改写 java实现html

static Map<String,String> html_specialchars_table = new Hashtable<String,String>();
    static {
        html_specialchars_table.put("&lt;","<");
        html_specialchars_table.put("&gt;",">");
        html_specialchars_table.put("&amp;","&");
        html_specialchars_table.put("&quot;","\"");
    }
    static String htmlspecialchars_decode(String s){

        for (Map.Entry entry : html_specialchars_table.entrySet()) {

            Object key = entry.getKey( );
            String val = html_specialchars_table.get(key);
            s = s.replaceAll(key.toString(), val);
        }

        return s;
    }

因为使用的thymeleaf 引擎,因此必须使用标签 th:utext ,java

相关文章
相关标签/搜索