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.
Asked
Active
Viewed 82 times
3 Answers
2
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.

npinti
- 51,780
- 5
- 72
- 96
-
_Since you have mentioned database, I am assuming that you have Java involved_ Not really true, the OP could have a PHP bridge to the database that he accesses with AJAX, so it would be Javascript. In fact he talks about a _page_ which seems to be a _webpage_. There aren't much informations to provide a complete answer – BackSlash Sep 18 '13 at 09:29
1
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
0
Write a function on java side which will convert all these or expected special characters and will return to front end.
e.g.
function String convert(String var){
var.replace(/&/g,"&").replace(/>/g,">");
}

abcd
- 3,164
- 2
- 18
- 13