日期:2014-05-18  浏览次数:20601 次

如何保存文本框输入的格式
在一个大的文本框输入一段文字后,如何保存才能在下一个页面收到后能够按原
来的格式输出。有没有这样的方法,还是要自己写段怎么样的代码?

知道的帮忙解决下,谢谢!   :)

------解决方案--------------------
要把文本中的换行,空格,还有一些特殊的字符转换为html中的字符。
网上的例子很多的
------解决方案--------------------
请看下面这个例子
 public static String escapeHTMLTags( String input ) {
    // Check if the string is null or zero length -- if so, return what was sent in.
    if( input == null || input.length() == 0 ) {
      return input;
    }
    // Use a StringBuffer in lieu of String concatenation -- it is much more efficient this way.
    StringBuffer buf = new StringBuffer();
    char ch = \ ' \ ';
    for( int i=0; i <input.length(); i++ ) {
      ch = input.charAt(i);
      if( ch == \ ' <\ ' ) {
        buf.append( \ " <\ " );
      }
      else if( ch == \ '> \ ' ) {
        buf.append( \ "> \ " );
      }
      else {
        buf.append( ch );
      }
    }
    return buf.toString();
  }


------解决方案--------------------
就是把你从文本区接收到的大字符串进行分析,然后转化成相应的HTML标签。