eWebEditor Manual V11.2 : Developer Guide : Reference forServer Function : JSP : htmlEncode
eWebEditor Home >> eWebEditor Manual V11.2 >> Developer Guide >> Reference forServer Function >> JSP htmlEncode

The function of this function is similar to the following functions in other environment.

(ASP/ASP.net): Server.HTMLEncode()

(PHP): htmlspecialchars()

This function is often used in content modification. When you want to read out the content  saved in database and modify it in the editor, you need to encode HTML format at first, and then set the initial value of <textarea>.

The function code is listed as follows


static String htmlEncode(int i){

       if (i=='&') return "&amp;";

       else if (i=='<') return "&lt;";

       else if (i=='>') return "&gt;";

       else if (i=='"') return "&quot;";

       else return ""+(char)i;



static String htmlEncode(String st){

       StringBuffer buf = new StringBuffer();

       for (int i = 0;i<st.length();i++){



       return buf.toString();



Modifcation example:

Pay attention to the blue part in the following example. The form is calculated to set value for the editor. Variable str points to the initial value of HTML format from database.

<textarea name="content1" style="display:none"><%=htmlEncode(str)%></textarea>

<IFRAME ID="eWebEditor1" src="../ewebeditor.htm?id=content1&style=coolblue" frameborder="0" scrolling="no" width="550" height="350"></IFRAME>