Func.jsp
上传用户:huijianzhu
上传日期:2009-11-25
资源大小:9825k
文件大小:1k
源码类别:

电子政务应用

开发平台:

Java

  1. <%!
  2.   public static String toHtml(String s) {
  3.       s = Replace(s,"&","&amp;");
  4.       s = Replace(s,"<","&lt;");
  5.       s = Replace(s,">","&gt;");
  6.       s = Replace(s,"t","    ");
  7.       s = Replace(s,"rn","n");
  8.       s = Replace(s,"n","<br>");
  9.       s = Replace(s," ","&nbsp;");
  10.       s = Replace(s,"'","&#39;");
  11.       s = Replace(s,"\","&#92;");
  12.       return s;
  13.     }
  14.     //字符串本身有replace函数。
  15.     public static String Replace(String source,String oldString,String newString) {
  16.       if(source == null) return null;
  17.       StringBuffer output = new StringBuffer();
  18.       int lengOfsource = source.length();
  19.       int lengOfold = oldString.length();
  20.       int posStart = 0;
  21.       int pos;
  22.       while((pos = source.indexOf(oldString,posStart)) >= 0) {
  23.         output.append(source.substring(posStart,pos));
  24.         output.append(newString);
  25.         posStart = pos + lengOfold;
  26.       }
  27.       if(posStart < lengOfsource) {
  28.         output.append(source.substring(posStart));
  29.       }
  30.       return output.toString();
  31.   }
  32.   public static String toEnHtml(String s) {
  33.       s = Replace(s,"&amp;","&");
  34.       s = Replace(s,"&lt;","<");
  35.       s = Replace(s,"&gt;",">");
  36.       s = Replace(s,"    ","t");
  37.       s = Replace(s,"n","rn");
  38.       s = Replace(s,"<br>","n");
  39.       s = Replace(s,"&nbsp;"," ");
  40.       s = Replace(s,"&#39;","'");
  41.       s = Replace(s,"&#92;","\");
  42.       return s;
  43.     }
  44. %>