vendredi 1 septembre 2017

Problems with the encoding in the JSP on Glassfish (js gets the data in the wrong encoding)

JSP contains:

<%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" language="java" %>
... 
<meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
...
<script>
    function setconfig() {    
        var msg = encodeURI($('#setconfig').serialize());
        alert(msg);
        $.ajax({
            type: 'POST',
            url: 'sps',
            data: msg,
            success: function (data) {
                $('#results').html(data);
            },
            error: function (xhr, str) {
                alert('Возникла ошибка: ' + xhr.responseCode);
            }
        });
    }
</script>
...
<form method="POST" id="setconfig" action="javascript:void(null);" onsubmit="setconfig()">
  <input name="http_port" value="${configMap.get("http_port")}" size="30"/>
  <input type="submit" value="Изменить"/>
</form>

When you enter "абв" on the form, the message (pic) with the wrong encoding.

Installing UTF-8 encoding in scriptlet for regress and response does not help.

if <%out.println(Charset.defaultCharset());%>, then out "windows-1251"

sun-web.xml contains:

 <locale-charset-info>
    <parameter-encoding default-charset="UTF-8" />
 </locale-charset-info>

IDE: Intellij IDEA

Aucun commentaire:

Enregistrer un commentaire