Jeesite CKEditor Database HTML is encoded problem solved

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.