Java HTMLEncode & HTMLDecode

package com.rf.demo;   
 
import org.apache.commons.lang.StringEscapeUtils;
 
/**  
 * 替换HTMl里面的字符 e.g.: < > " å И 水  
 *   
 * @author ivan.yan
 */  
public class EscapeUtils {   
 
  public static void main(String[] args) {
      String s = "中文转字符的HTML实体表示形式";
      System.out.println(StringEscapeUtils.escapeHtml(s));
      
      
      String u = "&#20013;&#25991;&#36716;&#23383;&#31526;&#30340;HTML&#23454;&#20307;&#34920;&#31034;&#24418;&#24335;";
      System.out.println(StringEscapeUtils.unescapeHtml(u));
      
  }
}
展开阅读全文

HtmlEncode/HtmlDecode问题

11-18

我在TextBox(TextMode:MultiLine)中写数据,然后用HtmlEncode()保存在数据库,然后用HtmlDecode读出来,读出来在TextBox(TextMode:MultiLine)中能够正确显示,但是TextMode:MultiLine的TextBox有个滚动条很不好看,于是我用Label或直接输出,试了却不能正确显示(该换行的地方不换行了。。。。。)?rnrn另一个问题是我都用TextBox(TextMode:MultiLine)来写和显示数据可以正确换行和显示文字,但我保存代码如下的代码就不行了(下边的这些代码插不进数据库,也没有任何错误信息),rnrn下面是我想存入数据库的文本:rnprotected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)rn rn rn if (e.Row.RowType == DataControlRowType.DataRow)rn rn int money = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "MONEY"));rn if (money == 77)rn e.Row.BackColor = Color.Red;rn string customer = DataBinder.Eval(e.Row.DataItem, "CUSTOMER").ToString();rn if (customer == "sdf")rn e.Row.BackColor = Color.Red;rn rn if (e.Row.RowType == DataControlRowType.DataRow rn rn e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='yellow',this.style.fontWeight='';");rn e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';"); rn rn if (e.Row.RowType == DataControlRowType.DataRow)rn rn  e.Row.Attributes.Add("onclick","this.style.backgroundColor='#99cc00'; this.style.color='buttontext';this.style.cursor='default';");rn rn 论坛

没有更多推荐了,返回首页