Gaurav Mahindra Gaurav Mahindra - 4 months ago 32
HTML Question

How to save HTML code in Sql Server database for correct display?

My website is just like Stack Overflow and under development. I am using plain textarea to take text input as I do not have any WMD editor like Stack Overflow's.

When I take HTML code as input and store it in database table in a text or

column, it is stored successfully. But when I call that data for display, it displays the corresponding HTML page instead of that HTML code on screen. I am not able to resolve it. For better understanding I'm putting here input page and output page images of my website.

This is image of input page:

enter image description here

This is the image of output page:

enter image description here

What is going wrong here ?


Another possible solution is to replace the html tags before storing in database. What I did is :-

text=text.replaceAll("<", "&lt;");
text=text.replaceAll(">", "&gt;");

and then stored text in database and its working. Thanks to Bibin Mathew.