现在有个需求要将 textarea控件中格式 完整的保存到数据库中,然后 从数据库中读取出来的时候再将内容按照原来的个数显示出来,希望谁能给提供个完整的例子!谢谢了!

解决方案 »

  1.   

    使用文本编辑器 貌似可以, 保存到数据库时会连格式一起保存。
    现在比较流行的貌似是 FCK编辑器。网上有免费源码
      

  2.   

    显示在哪里 textarea控件还是直接显示在页面上
      

  3.   

      private static final String _BR = "<br/>";  /**
       * 在页面上直接显示文本内容,替换小于号,空格,回车,TAB
       * 
       * @param str String 原始字符串
       * @return String 替换后的字符串
       */
      public static String htmlshow(String str) {
        if (str == null) {
          return null;
        }    str = replace("<", "&lt;", str);
        str = replace(" ", "&nbsp;", str);
        str = replace("\r\n", _BR, str);
        str = replace("\n", _BR, str);
        str = replace("\t", "&nbsp;&nbsp;&nbsp;&nbsp;", str);
        return str;
      }用这个方法过滤一下再显示
      

  4.   

      public static String replace(String from, String to, String source) {
        if (source == null || from == null || to == null)
          return null;
        StringBuffer bf = new StringBuffer("");
        int index = -1;
        while ((index = source.indexOf(from)) != -1) {
          bf.append(source.substring(0, index) + to);
          source = source.substring(index + from.length());
          index = source.indexOf(from);
        }
        bf.append(source);
        return bf.toString();
      }