First, please let me say that I recognize that having html saved in MySQL db is not ideal. But that's the way it's been setup and I just have to accept it and work with the existing set up.
So here's my issue.
I have a table "messages" that has "message" and "time" columns.
These are some sample values just for demonstration purposes:
MySQL: "message" column:
You've received an appraisal from xyz re something in the amount of $1,2000.<br><a class='lnk' href='http://www.website.com/somepage.jsp?r=393'>View some page</a>
"time" column:
2015-12-16 15:51:33.0
I can retrieve the values in a java class and convert the resultset data into a jsonArray.
If I sysout the jsonArray, I can see the values from the table displayed more or less correctly.
System.out.println("jsonArray: " + jsonArray);
Output:
jsonArray: [{"message":"You've received a message from xyz re something in the amount of $1,200.<br><a class='lnk' href='http://www.website.com/somepage.jsp?r=393'>View some page<\/a>","time":"2015-12-16 15:51:33.0"}]
I am struggling with two issues:
1) Returning html tags without being escaped in the output
Please notice the escaped closing tag: </a> in the jsonArray above. Is there a way to retrieve it without the escape?
2) Returning jsonArray in jsp properly formatted and escaped.
I would like the JSP to return the jsonArray but I am not having much luck getting things to work correctly More specifically, I tried the following two to output the jsonArray on my jsp page:
out.print(jsonArray);
out.println(jsonArray.toString());
But in both cases, the escaped closing tags seems to be causing issues. The jsp output looks like this:
And this is the code generated in the jsp.
[{"message":"You've received an appraisal from xyz re something in the amount of $1,2000.<br><a class="lnk" href="http://www.website.com/somepage.jsp?r=393">View some page<\/a>","time":"2015-12-16 15:51:33.0"}]
Please notice the
<\/a>
Could anyone please give me some tips how to properly format html tags in a jsonArray that contains data fetched from a database?
Thank you!

<a>tag first, because it's messing up your JSON and making it invalid (use JSONLint to check). Any specific reasons for not escaping it? It seems like your JSON response is returningtext/htmlinstead ofapplication/json, is that intended?