提供Web相关的个工具类
package com.opslab.util.web;
import com.opslab.util.ConvertUtil;
import com.opslab.util.StringUtil;
import java.io.UnsupportedEncodingException;
/**
* 提供Web相关的个工具类
*/
public final class WebUtil {
/**
* 对字符串进行编码
*
* @param str 需要处理的字符串
* @param encoding 编码方式
* @return 编码后的字符串
*/
public static String escape(String str, String encoding) throws UnsupportedEncodingException {
if (StringUtil.isEmpty(str)) {
return "";
}
char[] chars =ConvertUtil.bytesToChars(ConvertUtil.encodeBytes(str.getBytes(encoding), '%'));
return new String(chars);
}
/**
* 对字符串进行解码
*
* @param str 需要处理的字符串
* @param encoding 解码方式
* @return 解码后的字符串
*/
public static String unescape(String str,String encoding){
if(StringUtil.isEmpty(str)){
return "";
}
return UrlUtil.decodeQuery(str, encoding);
}
/**
* HTML标签转义方法
*
* 空格
< 小于号 <
> 大于号 >
& 和号 &
" 引号 "
' 撇号 '
¢ 分 ¢
£ 镑 £
¥ 日圆 ¥
€ 欧元 €
§ 小节 §
© 版权 ©
® 注册商标 ®
™ 商标 ™
× 乘号 ×
÷ 除号 ÷
*/
public static String unhtml(String content) {
if (StringUtil.isEmpty(content)) {
return "";
}
String html = content;
html = html.replaceAll("'", "'");
html = html.replaceAll("\"", """);
html = html.replaceAll("\t", " ");// 替换跳格
html = html.replaceAll("<", "<");
html = html.replaceAll(">", ">");
return html;
}
public static String html(String content) {
if (StringUtil.isEmpty(content)) {
return "";
}
String html = content;
html = html.replaceAll("'", "'");
html = html.replaceAll(""", "\"");
html = html.replaceAll(" ", " ");// 替换跳格
html = html.replaceAll("<", "<");
html = html.replaceAll(">", ">");
return html;
}
}
相关文章
- NLP工具最新版Spacy及语言包en_core_web_sm下载安装指南
- Web报表工具FineReport二次开发JS之字符串
- PIPE2——Petri网编辑工具
- pyDash:一个基于 web 的 Linux 性能监测工具
- Web安全 Acunetix漏洞扫描工具.(破解版)
- Web文件管理、私有云存储管理工具 DzzOffice
- 基于.htaccess的Web Shell工具htshells
- 小型Web应用扫描工具Grabber
- gshark-敏感信息搜集防泄漏图形化工具(避坑指南)
- 【漏洞扫描工具】Acunetix-Web应用系统漏扫工具
- Caffe学习系列(21):caffe图形化操作工具digits的安装与运行
- Web开发相关工具收集
- 微软商店上架Windows&Office破解工具,并获5星好评?
- 《iOS 8案例开发大全》——实例010 使用第三方工具iPhone Simulator
- 《重构HTML:改善Web应用的设计(修订版)》——第2章 工具 2.1 备份、测试用机和源码控制
- 如何使用工具下载B站非会员视频(下载B站免费web视频)
- 工具 | 2的次方对照表
- 移动分析和营销工具服务公司Repro获得260万美元融资
- web配置nagios工具
- Badboy工具应用技巧
- 工具说明书 - 网页内容抓取工具Web Scraper(一)
- 很好用的Unity编辑器扩展工具 Odin Inspector教程