Plain text shows Encoded Chars
Just started to have a chance to try out Spring 3.0, a lot of new features introduced, yet not enough time to read up all features.
I started a simple web apps project to try out Spring 3.0. The web apps is pretty simple, a REST server alike. Client init HTTP calls to the web apps with specific Servlet name and parameter, the web apps will returns the result JSON with Plain text mode. Since I am using Spring MVC, the result is printed with JSTL.
Sample call from client: http://myserver.com/getUser?userId=001
Expected result from server:
{“name”:”Bob”,”age”:”30″,”gender”:”male”}
I get what I expected when I test my web apps with browser.
But the ‘interesting’ comes when I test it with little Java Post program (use HttpClient, init HTTP call and inspect the result).
I did not get the expected result, I get below:
{"name":"Bob","age":"30","gender":"male"}
All double-quat / quotation being replaced with ", its clearly the contain is being HTML encoded.
Below are my trouble-shooting steps:
Step 1. Check tomcat configuration
– Ensure the tomcat UTF-8 by default. More info
Step 2. Check web apps JSPs
– Ensure all JSP are UTF-8 as default encoding.
But both Step 1 & 2 does not fix my problem yet.
Step 3. Google “jstl without html encoded”
– Finally, I get the answer 🙂
– add in escapeXML properties when printing the result in JSTL
Before: <c:out value="${result}" />
After: <c:out value="${result}" escapeXml=”false”/>
Tutorial – Output with / without Encode
Lesson Learn:
When you want to print a PLAIN TEXT with JSTL, do remember to include escapeXML="false"
to ensure that end user will get the actual expected result without HTML/XML encoded.
Leave a Reply