在開發(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, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
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> 內(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(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, '"');//將轉(zhuǎn)換后的字符串在進(jìn)行html標(biāo)簽的反編譯,(此處引用在Ext.util.Format.htmlDecode ,如果是ext數(shù)據(jù)提交直接Ext.util.Format.htmlDecode(content))
</script>
</span></td></tr>
.......