ResultSet data = new com.sourceware.test.Test().read();
                           //new一个Test类的对象,调用read()方法,返回一个ResultSet对象
while(data.next()) {
  content = data.getString("content");
  out.println(content);
}输出来的内容就一行,没人任何换行的!
求教啊,怎样才能显示正常!

解决方案 »

  1.   

    在content里面是一个字符串吗?应该按ID来取吧,然后也要写下格式
    out.println(content.xxx);
      

  2.   

    存入数据库要转的.用页面支持的<br>
    要不就拿出来再content.replaceAll("\r\n","<br>");
      

  3.   

    这个方法是对的
    但是如果平台不同的话,回车符也不一样
    建议改成
    content.replaceAll(Character.LINE_SEPARATOR," <br/>")
    BR是HTML的换行
    HTML4.0是要求所有的tag全部闭合的 所以要加/>
      

  4.   

    在用户存入数据的时候要先转换 把用户输入的数据获得到 做为参数 调用下面的方法:
    public static String replaceIn(String pstrWord) throws Exception {
            pstrWord = pstrWord.replaceAll("\n", "<br/>");
            pstrWord = pstrWord.replaceAll("<", "&lt;");
            pstrWord = pstrWord.replaceAll(">", "&gt;");
            return pstrWord;
        }
    然后把返回的这个字符串存入数据库,取出来的时候相反,把取出来的值做为参数调用下面的方法:
    public static String replaceOut(String pstrWord) throws Exception {
            pstrWord = pstrWord.replaceAll("&lt;br/&gt;", "\n");
            pstrWord = pstrWord.replaceAll("&lt;", "<");
            pstrWord = pstrWord.replaceAll("&gt;", ">");
            return pstrWord;
        }
    这样在输出就可以看到回车效果了