24 Mar 2015

Java/Jsp and the Euro Symbol €

To handle the € Euro Symbol in pages within a JSP/Java app, you better use the Windws-1252 charset encoding.
Just do the 2 following notes:

1) Put those lines in your jsp page to force the encoding in the response page:

<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page pageEncoding="windows-1252"%>


2) and then, before reading anything from the submitted pages, force the same encoding on the request:

request.setCharacterEncoding( "windows-1252" );

(*) this is needed because the browser may send back datas using their default encoding, and not the one you setted on your page, causing.


Last but not least, if you are going to write/read datas to a database, be careful to configure your db with a compatible encoding.
For example, on sql server, e dafault collation Latin1_General_CI_AS would be fine.

No comments: