你的textarea设成自动换行试试

解决方案 »

  1.   

    哦,应该是
    string.replaceAll("\n","<br>");
      

  2.   

    string.replaceAll("\n","<br>")没有这个函数。
    试试:
    int index=text.indexOf("\r\n");
    while(index!=-1)
    {
    text=text.substring(0,index)+"<br>"+text.substring(index+2);
    index=text.indexOf("\r\n");
    }
      

  3.   

    nanman(南蛮) 写的完整的函数:
     public static String toHTMLString(String in) {
            StringBuffer out = new StringBuffer();
            for (int i = 0; in != null && i < in.length(); i++) {
                char c = in.charAt(i);
                if (c == '\'')
                    out.append("&#039;");
                else if (c == '\"')
                    out.append("&#034;");
                else if (c == '<')
                    out.append("&lt;");
                else if (c == '>')
                    out.append("&gt;");
                else if (c == '&')
                    out.append("&amp;");
                else if (c == ' ')
                    out.append("&nbsp;");
                else if (c == '\n')
                    out.append("<br/>");
                else
                    out.append(c);
            }
            return out.toString();
        }