Alfred’s Computing Weblog

Alfred Java-cored Computing Weblog

Archive for the ‘HTML’ Category

Plain text shows Encoded Chars

leave a comment »

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.

Advertisements

Written by Alfred

June 28, 2011 at 15:54

Posted in HTML, Java, Spring

Tagged with ,

Html Form | GET vs POST

leave a comment »

Some simple stuff that a lot developers may mixup / confuse about — POST vs GET.

POST and GET are the most common use FORM submittion method used in html, as long as you’re working / doing in web application; you cant runaway from it.

Here is the simple comparison:

POST

  1. Form data will appear within a message body.
  2. More functionality: retrieves, stores, updates data, makes modifications to databases, and so on.
  3. Not cacheable.
  4. Can buffer long URLs.
  5. Considered more secure.

GET

  1. Form data is encoded by the browser into a URL.
  2. Best used for retrieving data.
  3. Cacheable.
  4. Cannot buffer long URLs.
  5. Considered less secure.

References:

1. http://www.peachpit.com/guides/content.aspx?g=webdesign&seqNum=69

2. http://www.cs.tut.fi/~jkorpela/forms/methods.html

Written by Alfred

November 6, 2008 at 16:01

Posted in HTML

Tagged with , , ,