用户在textarea中输入的回复信息
如果直接显示在页面上,不能显示其中的回车我看很多人都是转换一下回复信息,但是不到需要转换成什么样。
希望大家指点一下

解决方案 »

  1.   

    文本里的换行,在html里是不会被解析成换行的,你必须把文本里的换行替换成<br>标签
      

  2.   

    我也这么想过,可是对于字符串
    "ajkfakdf<br>sdfg"中的"<br>"通过页面显示并不会回车呀,显示的还是<br>呀?
    难道把文本中的换行转换成<br>就能够回车了吗?
    请赐教!!!
      

  3.   

    使用文本编辑器 比如说eWebEditor
      

  4.   

    下面这个就是我一直用的,html字符过滤工具,应该就是你要的public class CodeFilter{
    public CodeFilter(){
    }

    public static String toHtml(String s){
    if(s == null){
    s = "";
    return s;
    }
    s = Replace(s.trim(),"&","&amp;");
          s = Replace(s.trim(),"<","&lt;");
    s = Replace(s.trim(),">","&gt;");
    s = Replace(s.trim(),"\t","    ");
    s = Replace(s.trim(),"\r\n","\n");
    s = Replace(s.trim(),"\n","<br>");
    s = Replace(s.trim(),"  "," &nbsp;");
    //s = Replace(s.trim(),"'","&#39;");
    s = Replace(s.trim(),"\\","&#92;");
    return s;
      }
      public static String unHtml(String s){
    s = Replace(s,"<br>","\n");
    s = Replace(s,"&nbsp;"," ");
    return s;
    }//Replace
     public static String Replace(String source,String oldString,String newString){ StringBuffer output = new StringBuffer(); int lengthOfsource = source.length();
    int lengthOfold = oldString.length(); int posStart = 0;
    int pos; while((pos = source.indexOf(oldString,posStart)) >= 0){
    output.append(source.substring(posStart,pos));
    output.append(newString); posStart = pos + lengthOfold; } if(posStart < lengthOfsource){

            output.append(source.substring(posStart));
    }

    return output.toString();
     }
    }
      

  5.   

    谢谢了(zhangj0571(笨鸟飞飞))