In my application I retrieve String values from a database and before I display them on the webpage I want to make sure they are properly HTML encoded. For example, I might retrieve the value "AT&T" as a String from the database. Before outputing that String to a web page I probably ought to change the ampersand to the proper HTML encoding.
I have come across several examples on the web of people writing their own Java class to do this. I also understand there is a package called JTidy at SourceForge, but it looks to me like it hasn't been updated since around 2000.
My question is this - is there a good, supported, and well documented package out there that you would recommend for this purpose?
Thanks in advance for your help!
Bear Bibeault wrote:Why are you emitting HTML from a servlet rather than forwarding to a JSP when the servlet's job is done?
Actually, that is exactly what I am doing. Let's say I have a String in the servlet. I add it as attribute to the request and forward it to a JSP to display it.
What I wanted to do was to HTML encode the String _before_ I sent it to the JSP. If there were an easy way to do it in JSP that would be fine - I just don't know how to do that.
Peter Johnson wrote:Perhaps this recent discussion will help: http://www.coderanch.com/t/435951/Servlets/java/equivalent-c-out-escapeXML-true
Thanks! Actually this pointed me to the tool I really need, the JSTL core library function that will HTML encode the String for me. Obviously I am still learning a lot of this!