Why '<' is shown as & lt;
I am outputting a lowercase form, my java class, like this
String numQsAdded = "<div id='message1'>"+getQuestion()+"</div>"; This string is sent back to the client side as XMLHttpRequest. So, on my jsp page, I have a javascript warning method that prints the string returned from the server. it translates '<' to < and '>' before >
how can i avoid this?
I tried changing my line to:
String numQsAdded = "<div id='message1'>"+getQuestion()+">/div<"; but it has even worse consequences. then '&' translates to "amp"
Paul Fisher answers correctly. I'll think about why. HTML encoding of content from the server is a security measure to protect your users from script attacks. If you are just unescape () that comes from the server, you can put your users at risk as well as the reputation of your site.
Try to do what Paul said. It is not difficult and much safer. To facilitate this, here is a sample:
var divStuff = document.createElement('div'); divStuff.appendChild(containerElement); divStuff.id = 'message1'; divStuff.innerHTML = getQuestion(); It is much safer and provides better separation for your presentation level in your application.