http://www.csdn.net/expert/topic/783/783200.xml?temp=.5592768

解决方案 »

  1.   

    http://www.csdn.net/expert/topic/759/759652.xml?temp=.7651483
      

  2.   

    http://www.csdn.net/expert/topic/759/759652.xml?temp=.7651483
      

  3.   

    //禁用HTML代码编码
    public String html(String s){
    String re;
    re=replace(s,"<","&lt;");
        re=replace(re,">","&gt;");
        re=replace(re,"\n","<br>");
        re=replace(re," ","&nbsp;");
        re=replace(re,"'","&#39");
        return re;
    }把用户提交的东西,写数据库的时候先禁用html
      

  4.   

    //用指定的字符替换字符串中某个字符
    public String replace(String con,String tag,String rep){
    int j=0;
    int i=0;
    int k=0;
    String RETU="";
    String temp=con;
    int tagc=tag.length();
    while(i<con.length()){
    if(con.substring(i).startsWith(tag)){
    temp=con.substring(j,i)+rep;
    RETU+=temp;
    i+=tagc;
    j=i;
    }
    else{i+=1;
    }
    }
    RETU+=con.substring(j);
    return RETU;
    }//禁用HTML代码编码
    public String html(String s){
    String re;
    re=replace(s,"<","&lt;");
        re=replace(re,">","&gt;");
        re=replace(re,"\n","<br>");
        re=replace(re," ","&nbsp;");
        re=replace(re,"'","&#39");
        return re;
    }刚才少给了你一个函数
      

  5.   

    用这个试试
    public static String returnToBr(String sStr)
     { 
    if (sStr == null || sStr.equals(""))
     { 
    return sStr; 
    }  StringBuffer sTmp = new StringBuffer(); 
    int i = 0; 
    while (i <= sStr.length()-1)
     { 
    if (sStr.charAt(i) == '\n'||sStr.charAt(i)=='\r') 

    sTmp = sTmp.append("<br>"); 
    } else if (sStr.charAt(i)==' ')
     { 
    sTmp = sTmp.append("&nbsp;"); 
    }else
     { 
    sTmp = sTmp.append(sStr.substring(i,i+1)); 
     } 
    i++; 

    String S1;
    S1=sTmp.toString();
    return S1;