Forum Stats

  • 3,837,410 Users
  • 2,262,256 Discussions
  • 7,900,273 Comments

Discussions

setCharacterEncoding method not encoding properly with iso-8859-15 for special characters

3440673
3440673 Member Posts: 1
edited Apr 27, 2017 11:53AM in Java Servlet

I have simple form submit flow, the requesting is going throw the filter before it is receiving by Servlet. In my doFilter method the first line itself is setting the Character Encoding with iso-8859-15 as shown below

<span class="kwd" style="color: #101094;">public</span><span class="pln" style="color: #303336;"> </span><span class="kwd" style="color: #101094;">void</span><span class="pln" style="color: #303336;"> doFilter</span><span class="pun" style="color: #303336;">(</span><span class="typ" style="color: #2b91af;">ServletRequest</span><span class="pln" style="color: #303336;"> servletRequest</span><span class="pun" style="color: #303336;">,</span><span class="pln" style="color: #303336;"> </span><span class="typ" style="color: #2b91af;">ServletResponse</span><span class="pln" style="color: #303336;"> servletResponse</span><span class="pun" style="color: #303336;">,</span><span class="pln" style="color: #303336;"> </span><span class="typ" style="color: #2b91af;">FilterChain</span><span class="pln" style="color: #303336;"> chain</span><span class="pun" style="color: #303336;">)</span><span class="pln" style="color: #303336;"> </span><span class="kwd" style="color: #101094;">throws</span><span class="pln" style="color: #303336;"> </span><span class="typ" style="color: #2b91af;">IOException</span><span class="pln" style="color: #303336;"> </span><span class="pun" style="color: #303336;">{</span><span class="pln" style="color: #303336;"> servletRequest</span><span class="pun" style="color: #303336;">.</span><span class="pln" style="color: #303336;">setCharacterEncoding</span><span class="pun" style="color: #303336;">(</span><span class="str" style="color: #7d2727;">"iso-8859-15"</span><span class="pun" style="color: #303336;">);</span><span class="pln" style="color: #303336;"> </span><span class="com" style="color: #858c93;">//encoding setting</span>

In my request object, I have a parameter called "name" which is holding value as "1Depósito" (i.e. International language special characters). The parameter value is modifying once setCharacterEncoding method executes. The parameter value is encoding to "1Depósito" instead of "1Depósito"

In my parameter value we have a special character "ó" (i.e. ASCII code 243) because of this it is not encoding properly but I believe iso-8859-15 is supporting "ó" character so then why it is not encoding properly?

NOTE:

  • If I change my encoding to "UTF-8" from "iso-8859-15" then it is working fine but I need to work with "iso-8859-15" only as the special character "ó" is valid for "iso-8859-15".

Kindly confirm that is "iso-8859-15" is supporting "ó" characters? if yes, then why encoding is not working?

Looking forward to your valuable inputs.

Thanks, BSK

This discussion has been closed.