Problem with encoding using websphere

0

Well, the fact is that in my html header I have the tags:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

everything works correctly except a search engine, which when looking for the ñ does not find anything, to fix it in my websphere server I added as a generic JVM argument the following: -Dclient.encoding.override = UTF-8 and this started to work correctly but nevertheless when selecting data with tildes and trying to press some update button or query in relation to that data it takes me to the generic error window since the data with the tilde picks them up as unrecognizable (only that or those letters that they have the accent).

    
asked by Javier GT 29.07.2016 в 12:29
source

2 answers

3
  

... everything works correctly except a search engine ...

If you add the property -Dclient.encoding.override=UTF-8 , you are telling WebSphere what encoding to use (only when this not is specified, eg: 'application/x-www-form-urlencoded; charset=UTF-8' ) to read the parameters of the content of a request POST or the parameters in a query string . Different from -Dfile.encoding=UTF-8 , which will change the default encoding used when reading or writing files, etc.

If before specifying this property, the search engine did not work correctly, that could mean that the search engine sent the data encoded in UTF-8, but WebSphere decoded it using ISO-8859-1.

For example, the word IBAÑEZ can be sent as IBA%C3%91EZ (UTF-8) or IBA%D1EZ (ISO-8859-1). If the server receives IBA%C3%91EZ (UTF-8), then WebSphere could decode it in UTF-8 as IBAÑEZ ( IBA\u00D1EZ ) ✔ or ISO-8859-1 as IBAÃEZ ( IBA\u00C3\u0091EZ ) ✘.

  

... however, when selecting data with accents and trying to press an update or query button in relation to that data, it takes me to the generic error window since the data with the tilde collects them as unrecognizable ...

Assuming that all worked correctly before adding the property -Dclient.encoding.override=UTF-8 , then that means that it is decoding with UTF-8 the data received as ISO-8859-1 . That is, if WebSphere receives IBA%D1EZ (ISO-8859-1), it now decodes it in UTF-8 as IBA�EZ ( IBA\uFFFDEZ ) ✘.

You must make sure that the data is sent as UTF-8. If you have forms that are sent without AJAX, then add the accept-charset attribute. It is is:

<form … accept-charset="UTF-8" … >

With JavaScript, use the function encodeURI() or encodeURIComponent() (depending on the case) to encode the data to be sent in UTF-8 with AJAX. jQuery uses UTF-8 to encode objects (eg: { nombre: var2 } ) in data .

In case you change the header of the JSPs to UTF-8 (also changing the encoding of the file itself), the above may be optional in most browsers, except possibly in Internet Explorer .

    
answered by 29.07.2016 в 18:23
2

The encoding of the JVM now is in UTF-8, and what you send from the JSP is charset = ISO-8859-1, it possibly generates characters that it does not recognize as those with a tilde: success Success Try leaving the same encoding to your JSP view:

It is recommended to use the same encoding that you have in the Meta, UTF-8 is wider than Latin 1 (another name of iso-8859-1), has more characters and therefore can be used for many more languages without problems.

<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
answered by 29.07.2016 в 16:41