Today, I was integrating a custom JSP component into IBM WCM and I noticed some characters were not displaying as expected, after looking into the generated source code in Firefox I realized the used encoding was ISO-8859-1, let me explain what ISO-8859-1 means…
According the W3C the ISO-8859-1 encoding:
ISO-8859-1 is the default character set in most browsers.
The first 128 characters of ISO-8859-1 is the original ASCII character-set (the numbers from 0-9, the uppercase and lowercase English alphabet, and some special characters).
The higher part of ISO-8859-1 (codes from 160-255) contains the characters used in Western European countries and some commonly used special characters.
Entities are used to implement reserved characters or to express characters that cannot easily be entered with the keyboard.
My source code looked like this (in Firefox):
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
And this was the displayed characters (look the “Spanish”, “Portuguese” and “Russian” language labels):
Well, solution for this enconding error is really easy, we only need to:
1) Set the encoding in the JSP file (using your editor or IDE), in my case I was using Rational:
2) Type a directive to indicate we WANT to use UTF-8. At the beginning of your JSP code add following line:
<%@page language="java" contentType="text/html; charset=utf-8" %>
That’s it! now all our messages will be ok 🙂
Be happy with your code!
2 comments on “Setting UTF-8 encoding in a JSP (changing ISO-8859-1 to UTF-8 on IBM Rational Application Developer)”
Hi Alex, I just found this. This is exactly what I am trying to accomplish but it’s not working for me. My characters are still displayed like your first image. I’ve made the changes you show but it isn’t working. Any thoughts on what the do next? Thanks!
How about trying to save your JSP using other code editor like Sublime Text or Notepad++ for example: http://www.alex-arriaga.com/wp-content/uploads/2016/09/save-utf-8-without-bom.jpg