JAVA中转换HTML代码

java 代码
  1. package com.wide.cabaret.utils;   
  2.   
  3. public class Html{   
  4.   public Html(){   
  5.     super();   
  6.   }   
  7.   
  8.   public String toHtml(String str){   
  9.     if (str==null){   
  10.       return "";   
  11.     }else{   
  12.       str=str.replaceAll("<""&lt;");   
  13.       str=str.replaceAll(">""&gt;");   
  14.       str=str.replaceAll("'""''");   
  15.       str=str.replaceAll(" ""&nbsp;");   
  16.       str=str.replaceAll("\n""<br>");   
  17.     }   
  18.     return str;   
  19.   }   
  20.   
  21.   public String toText(String str){   
  22.     if (str==null){   
  23.       return "";   
  24.     }else{   
  25.       str=str.replaceAll("&lt;""<");   
  26.       str=str.replaceAll("&gt;"">");   
  27.       str=str.replaceAll("''""'");   
  28.       str=str.replaceAll("&nbsp;"" ");   
  29.       str=str.replaceAll("<br>""\n");   
  30.     }   
  31.     return str;   
  32.   }   
  33. }   

你可能感兴趣的:(java,html)