Public Abstract classBasecontroller {/** * Initialize Data binding * 1. HTML encoding of all strings passed in to prevent XSS attacks * 2. Convert a date type in a field to a string type*/@InitBinderprotected voidInitbinder (Webdatabinder binder) {//String type conversion, HTML encoding of all incoming strings to prevent XSS attacksbinder.registercustomeditor (String.class,NewPropertyEditorSupport () {@Override Public voidSetastext (String text) {SetValue (text==NULL?NULL: stringescapeutils.escapehtml4 (Text.trim ())); } @Override PublicString Getastext () {Object value=GetValue (); returnValue! =NULL? Value.tostring ():""; } }); //...}
The key sentence we see is: STRINGESCAPEUTILS.ESCAPEHTML4 (Text.trim ()));
So when you want to save HTML content in a database, there are two things you need to change:
1.JSP:
<div class= "Control-group" ><label class= "Control-label" > Product Details: </label><div class= "Controls" ><form:textarea id= "Detail" htmlescape= "true" rows= "4" maxlength= "1024x768" class= "Input-xxlarge"/ ><sys:ckeditor replace= "Detail" uploadpath= "/cms/article"/></div></div>
Key sentence: Htmlescape= "true"
2.controller
Before saving: Perform the decoding operation.
Ecproduct.setdetail (stringescapeutils. UnescapeHtml4(ecproduct.getdetail (). Trim ()));
PostScript: As to why the article in the CMS can be added without decoding, the database is stored in HTML format that, I have not figured out, if you have high understanding please leave a message to tell thanks.
Jeesite CKEditor Database HTML is encoded problem solved