java 代码
- package com.wide.cabaret.utils;
- public class Html{
- public Html(){
- super();
- }
- public String toHtml(String str){
- if (str==null){
- return "";
- }else{
- str=str.replaceAll("<", "<");
- str=str.replaceAll(">", ">");
- str=str.replaceAll("'", "''");
- str=str.replaceAll(" ", " ");
- str=str.replaceAll("\n", "<br>");
- }
- return str;
- }
- public String toText(String str){
- if (str==null){
- return "";
- }else{
- str=str.replaceAll("<", "<");
- str=str.replaceAll(">", ">");
- str=str.replaceAll("''", "'");
- str=str.replaceAll(" ", " ");
- str=str.replaceAll("<br>", "\n");
- }
- return str;
- }
- }
本文介绍了一个Java工具类,用于将字符串转换为HTML实体形式,并提供了逆向转换的方法。该工具类能够帮助开发者避免XSS攻击,确保网页内容的安全显示。
904

被折叠的 条评论
为什么被折叠?



