我做了一个新闻发布系统,所有文本均存到数据库中,但是不能保存格式,如空格,回车等均不能显示,所有内容均连在一起,请问怎么解决呀!!在线等……

解决方案 »

  1.   

    你在把内容放到数据库之前,加个<br>。就是把你的内容先replaceAll("\r","<br>"),然后再加进数据库。
      

  2.   

    用 flyer007(飞翔鸟) 的方法。准沒錯。
    replaceAll("\r","<br>")
    replaceAll("\n","<br>"),
      

  3.   

    function htmlencode(str)
    if request("html")="1" then
    htmlencode=replace(replace(str,chr(13),"<br>"),"'","’")
    else
    htmlencode=server.htmlencode(str)
    htmlencode=replace(replace(replace(replace(str,"<","&lt;"),">","&gt;"),chr(13),"<br>")," ","&nbsp;") 
        htmlencode=replace(replace(replace(replace(replace(replace(htmlencode,"","></img>"),"","</b>"),"[/red]","</font>"),"[/big]","</font>"),"[/blue]","</font>"),"[/lime]","</font>")
    end if
    end function你可以参照一下这个,我用asp做的
      

  4.   

    通常建议出库时才替换的吧。要不做修改新闻的时候会看到一大堆的<br>
      

  5.   

    谁有java代码呀,贴出来我学习一下!谢谢!!
      

  6.   

    我顶!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!中国IT人才网(    http://www.itbbs.net.cn    )!
    免费招聘、求职。IT人工作的天堂。希望能够为大家所用。
      

  7.   

    <%!
    String Replace(String str_source, String str_original, String str_new){
    if(str_source == null)
    return null;
    StringBuffer output = new StringBuffer();
    int lengOfsource = str_source.length();
    int lengOfold = str_original.length();
    int posStart = 0;
    int pos;
    while((pos = str_source.indexOf(str_original, posStart)) >= 0){
    output.append(str_source.substring(posStart, pos));
    output.append(str_new);
    posStart = pos + lengOfold;
    }
    if(posStart < lengOfsource){
    output.append(str_source.substring(posStart));
    }
    return output.toString();
    }

    String toHtml(String s){
    s = Replace(s, "<", "&lt;");
    s = Replace(s, ">", "&gt;");
    s = Replace(s, "&", "&amp;");
    s = Replace(s, "\t", " ");
    s = Replace(s, "\r\n", "\n");
    s = Replace(s, "\n", "<br>");
    s = Replace(s, " ", "&nbsp;");
    s = Replace(s, "'", "&#39;");
    s = Replace(s, "\\", "&#92;");
    return s;
    }

    String unHtml(String s){
    s = Replace(s, "&nbsp;"," ");
    s = Replace(s, "<br>", "\n");
    return s;
    }
    %>
      

  8.   

    在你取出字符的时候可以使用这两个方法
    replaceAll("\r","<br>")
    replaceAll("\n","<br>"),
    如:
    String content = newsinfo.getContent;//取出数据库中的值
    String content1 = "";
    if(content!=null){
       content1 = content.replaceAll("\n","<br>");//得到回车
    }然后就可以将content1写在你的表单中,这样就可以得到你所要的了
      

  9.   

    出库替换。或者用html编辑器。
      

  10.   

    最简单的是加个HTML编辑器,嵌套一下就可以吧