Problem with the encoding of accents

Asked

Viewed 474 times

1

I am developing an application in Java Web, and I have an encoding problem.

On my page already contains the following Tags:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Then I put a alert in Javascript to output the Nome and Local, and the exit came normal with accent and cedilla (c).
But as soon as I send the Nome and the Local to the servlet and give a system.out.println he displays like this:

Nome = úúú ééé ááá ligações 
Local = São Vicente

Follows below code of servlet.

request.setCharacterEncoding("UTF-8");,
String nomeCompleto = request.getParameter("nome");
String local= request.getParameter("PA");
System.out.println("Nome = "+nomeCompleto+" ## local = "+local);

I don’t know where the coding problem is, I’ve tried everything.


How do you send this data to Servlet? Use one of the HTML? Ajax? Or something else? Put the code of that part in the question because I think the problem may be in it.

I use Ajax, I’m new to Jsp. The Function below is the one that sends the data I requested previously to Servlet.

function sendAddUser(){
var nome = document.getElementById("nomeCompletoTxt").value;
var boxName = document.getElementById("PA");
var PA = boxName.options[boxName.selectedIndex].value;


var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
    if(xhr.readyState == 4){
        if(xhr.responseText == 1){
            alert("nome = "+nome+" ## PA = "+PA);
            //window.location.href="#openSuccess";
        }
        else{
            window.location.href="#openError";
        }
    }
}
xhr.open("GET", "usuarioServlet?op=1&nome="+nome+"&PA="+PA);
xhr.send();

}

  • How do you send this data to Servlet? Use a <form> html? Ajax? Or something else? Put the code of that part in the question why I think the problem might be in it.

  • Have tried other Encodnig? Type ISO-8859-1?

  • 3

    @Joãomartins I don’t think it’s a good idea. If the text has emojis, for example, it’s impossible to code correctly with ISO-8859-1.

  • Ha, I didn’t know there could be something like that. So, no, it can’t be ISO.

  • You are using the Tomcat?

  • @Victorstafusa answered your question just below

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.