提供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;
}
}
最新文章
- 适合WebApi的简单的C#状态机实现
- Linux vi/vim(转载)
- CF735C 数论\平衡树叶子节点的最大深度\贪心\斐波那契\条件归一化
- matlab各格式数据读取与保存函数
- Sphinx中文分词详细安装配置及API调用实战
- Canvas与Image互转
- iOS应用架构谈 组件化方案
- android 多线程下载图片
- 【转】Android bluetooth介绍(二): android blueZ蓝牙代码架构及其uart 到rfcomm流程
- C语言循环的嵌套
- ExtJS简单的动画效果(ext js淡入淡出特效)
- C++单链表的创建与操作
- javascript 基础 onclick(this)用法介绍
- 从源码的角度看Service是如何启动的
- 逐步搭建Lamp环境之rpm软件包管理
- bzoj 1179: [Apio2009]Atm
- windows cmd下作MD5校验
- 流程帮App风险评估
- 使用uwsgi部署Django应用
- python-selenium,关于页面滑动的操作
热门文章
- 原生JavaScript和jQuery的较量
- 运行Vue项目,没办法自动打开浏览器,提示“Unable to open browser. If you are running in a headless environment, please do not use the open flag.”
- restful接口规范 | 基于restful的原生django接口
- [JSOI2018]战争
- LightOJ - 1311 - Unlucky Bird(相遇问题)
- CSS字体图标
- (23)打鸡儿教你Vue.js
- OpenStack Restful API框架介绍
- 【随记】Sql Server 2008 R2 备份时“无法打开备份设备”
- archlinux安装nvidia-1050ti闭源驱动教程,亲测