Sunday 22 November 2015

UTF- 8 Encoding in AEM

Set UTF-8 as Default Encoding : 

If we do not provide any charset encoding,  AEM uses " ISO-8859-1" as default encoding since this is mandated by Servlet API. But most of the times we need "UTF-8" encoding to support special characters and symbols in our multi lingual web sites.

Default Encoding can be configured within the OSGi configuration available http://localhost:4502/system/console/configMgr

AEM 6.1 : Go to Apache Sling Request Parameter Handling . Change the Default Parameter Encoding to "UTF-8"





AEM 5.6 : Go to Apache Sling Main Servlet . Change the Default Parameter Encoding to "UTF-8"




Encoding & Decoding while posting data to Sling Servlet :

Decoding  in the Servlet.

String id = java.net.URLDecoder.decode(request.getParameter("id"), "UTF-8");

Encoding data before posting to a  Servlet

String id= java.net.URLEncoder.encode("cust®", "UTF-8"); 

Set charset encoding in a JSP :


<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/libs/CFC/resources/jstl/c.tld" prefix="c" %>
<form method="post">
<input name="searchterm" value="<c:out value="${param.searchterm}" />" />
<input type="submit" />

</form>

We can even set encoding using response.setCharacterEncoding("UTF-8")




2 comments:

  1. Thanks you helped me resolve a problem between different server configurations!!!

    ReplyDelete
  2. I'm really impressed with your writing talents and also with the structure for your blog.

    Is that this a paid subject or did you modify it your self?
    Anyway keep up the excellent high quality writing, it's rare to peer a great weblog like this one these
    days..

    ReplyDelete