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;
    }

        
}

 

posted @ 2020-03-12 20:16  zcm1998  阅读(458)  评论(0编辑  收藏  举报