html文本存入数据库,特殊字符转换

package Controller;

public class TranslationStr {
    public String HtmltoStr(String newText) {
        
       // newText = newText.replace("\n", "<br>");
          //textBox里的换行是用\n来表示的,如果要在HTML里显示换行要用<br>
        newText = newText.replace("<", "&lt");  //置换 <
        newText = newText.replace(">", "&gt");  //置换 >
        newText=newText.replace("/", "&frasl");
          
        return newText;    
    }
    public String StrtoHtml(String newText) {
        //newText = newText.replace("<br>", "\n");  
        newText = newText.replace("&lt", "<");    
        newText = newText.replace("&gt", ">"); 
        newText=newText.replace("&frasl","/");
        return newText;
    }

        
}

 转载于:https://www.cnblogs.com/ZCM98/p/12482400.html

posted @ 2020-03-12 20:22  活出自己范儿  Views(666)  Comments(0Edit  收藏  举报