Tuesday, April 27, 2010

Charsets, PageEncodings and a JSP page.

I recently had an issue where the prototype HTML page for a JSP displayed OK on my browser but the converted JSP rendered some non-ASCII characters with weird symbols. To top that up, the JQuery animation refused to work.

The fix was simple, I had to re-save the .jsp file by providing a pageEncoding attribute at the top in my (Eclipse) IDE:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
so that the page characters will not be saved with the default JSP encoding of ISO-8859-1.

The charset (contentType="text/html; charset=UTF-8") is the encoding with which the rendered JSP (final output) will be served to a browser while the page encoding (pageEncoding="UTF-8") is the encoding which the JSP compiler will use to understand the contents of the JSP page (saved as a text file) so that it can compile it correctly to a .class file.

No comments:

Post a Comment