octscorpion

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            0 Posts :: 17 Stories :: 0 Comments :: 0 Trackbacks

          在開發(fā)過程出現(xiàn)這么一個(gè)問題:

             比如:一個(gè)字段content 類型CLOB,這其中存的有可能復(fù)制粘貼過來的word excel html中的內(nèi)容,用java將這些內(nèi)容存入,存入后有特殊的符號(hào) 比如回車換行等。那么不能正常展示的數(shù)據(jù)。

             解決方案:

             存入數(shù)據(jù)的是將這個(gè)數(shù)據(jù)contentdata在js中進(jìn)行

            String(contentdata).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");

          html標(biāo)簽編譯處理(此處引用在Ext.util.Format.htmlEncode ,如果是ext數(shù)據(jù)提交直接Ext.util.Format.htmlEncode(contentdata))

          在后臺(tái)用提交用

               Context initCtx = new InitialContext();     DataSource ds = (DataSource)JNDIUtil.lookup(initCtx) ;
               Connection conn = ds.getConnection();

               PreparedStatement ps=conn.prepareStatement("insert...values(?...)"),

               ps.setObject(5,contentdata)

               ......

            jsp中展示:sql語句中對(duì)此字段進(jìn)行這樣的處理:select REPLACE(REPLACE(content,chr(13),''),chr(10),'') content from table;

          輸出:

          .....

                <tr> <td><span>&nbsp;內(nèi) 容:</span></td><td><span id="content" >
                  <% String content=rs.getClob(5)==null?"":rs.getClob(5).getSubString((long)1, (int)rs.getClob(5).length());//讀取出clob數(shù)據(jù)進(jìn)行clob到字符串的轉(zhuǎn)換%>
                  <script>
                     document.getElementById("content").innerHTML=String("<%=content%>").replace(/&amp;/g, "&").replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"');//將轉(zhuǎn)換后的字符串在進(jìn)行html標(biāo)簽的反編譯,(此處引用在Ext.util.Format.htmlDecode ,如果是ext數(shù)據(jù)提交直接Ext.util.Format.htmlDecode(content))
                  </script>
                  </span></td></tr>

            
          .......

          posted on 2012-11-05 19:13 一G刀客 閱讀(1066) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 奉贤区| 松江区| 山阳县| 尼勒克县| 太原市| 河北区| 隆安县| 桃江县| 昌吉市| 崇信县| 嵊州市| 嘉兴市| 兰考县| 东明县| 济宁市| 师宗县| 阳新县| 宁海县| 冀州市| 突泉县| 内丘县| 宜川县| 乐山市| 涡阳县| 宜兰市| 宣恩县| 宣化县| 沾益县| 龙游县| 边坝县| 阿拉善盟| 祁阳县| 车致| 嘉鱼县| 镇宁| 沧州市| 清流县| 东兴市| 堆龙德庆县| 徐闻县| 莱芜市|