简体   繁体   中英

Display special characters in page

I'm having one div which will display some text. I'm getting this text from DB. This text can contains special characters like "\\",">","<" etc. When I'm trying to display this text in my page, these special characters wont be visible in my page for obvious reasons. So how to handle this situation.

Since you have mentioned database, I am assuming that you have Java involved...

That being said, you can take a look at Apache's StringEscapeUtils and escape your strings accordingly.

in your javascript you can write function, which will replace all the special characters with code

have a look at this answer Convert special characters to HTML in Javascript

Write a function on java side which will convert all these or expected special characters and will return to front end.

eg

function String convert(String var){
var.replace(/&/g,"&amp;").replace(/>/g,"&gt;");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM