Public classHtmlutilstest { Public Static voidMain (string[] args) {String specialstr= "The upstream of the animated film--"; String str1= Htmlutils.htmlescape (SPECIALSTR);//① conversion to HTML escape character representationSystem.out.println (STR1); String str2= Htmlutils.htmlescapedecimal (SPECIALSTR);//② conversion to data escape representationSystem.out.println (STR2); String STR3= Htmlutils.htmlescapehex (SPECIALSTR);//③ conversion to hexadecimal data escape representationSystem.out.println (STR3); //④ the inverse of the string in the face of escapeSystem.out.println (Htmlutils.htmlunescape (str1)); System.out.println (Htmlutils.htmlunescape (str2)); System.out.println (Htmlutils.htmlunescape (STR3)); // http://www.blogjava.net/i369/articles/236830.html //The Htmlutils provides three escape methods://Method Description//the static string Htmlescape (string input) escapes the HTML special character as an HTML universal escape sequence;//static string Htmlescapedecimal (string input) escapes the HTML special character as a band #//the decimal data escape sequence;//static string Htmlescapehex (string input) escapes the HTML special character as a band #//the hexadecimal data escape sequence;// //In addition, Htmlutils provides a way to restore escaped content: Htmlunescape (String//input), which can restore the contents of the above three escape sequences. Run the above code and you'll see the following output:// //Str1:<div id="testdiv">test1;test2</div> //str2:<div id= "Testdiv" >test1;test2</div>//str3:<div id= "Testdiv" >test1;test2</div>//<div id= "Testdiv" >test1;test2</div>//<div id= "Testdiv" >test1;test2</div>//<div id= "Testdiv" >test1;test2</div>// // // //you just use Htmlutils to escape the UserName and address of listing 1, and the final output of the HTML//the page will not be destroyed. }}
Java Escape Special characters