I'm getting strings in servlet
with accent problems.
Like for example:
Send $scope.nome = "Pé"
to servlet
.
In servlet
line: String nome = request.getParameter("nome");
does not receive Pé
and yes PÃc
File js
make the request:
var ajaxApp = angular.module("myApp", []);
ajaxApp.controller("gridUsersControl", [ '$scope', '$http', function($scope, $http) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=utf-8";
$scope.saveUser = function() {
var data = {
'action' : 'saveUser',
'id' : $scope.id,
'nome' : $scope.nome,
'sobrenome' : $scope.sobrenome,
'email' : $scope.email,
'telefone' : $scope.telefone,
'rua' : $scope.rua,
'bairro' : $scope.bairro,
'cidade' : $scope.cidade,
'estado' : $scope.estado,
}
$http({
contentType: "application/json; charset=utf-8",
url : 'UserController',
method : "POST",
params: data,
headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
}).then(function(response) {
$('#dialogEditUser').modal('hide');
generalDialog('Usuário cadastrado com sucesso.');
console.log(response.data);
angular.element(document.getElementById('principalUsers')).scope().loadUsers();
}, function(response) {
generalDialog('Problemas ao cadastrar usuário.');
console.log(response);
});
};
} ]);
My Servlet:
public class UserController extends HttpServlet{
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
request.setCharacterEncoding("UTF-8");
String action = request.getParameter("action");
switch(action){
case "saveUser":
saveUser(request, response);
}
}
private void saveUser(HttpServletRequest request, HttpServletResponse response) {
String id = request.getParameter("id");
String nome = request.getParameter("nome");
String sobrenome = request.getParameter("sobrenome");
String email = request.getParameter("email");
String telefone = request.getParameter("telefone");
String rua = request.getParameter("rua");
String bairro = request.getParameter("bairro");
String cidade = request.getParameter("cidade");
String estado = request.getParameter("estado");
Usuario user = null;
if(id != null){
user = (Usuario) PersistEngine.findById(Usuario.class, Integer.valueOf(id));
} else {
user = new Usuario();
}
user.setNome(nome);
user.setSobrenome(sobrenome);
user.setEmail(email);
user.setTelefone(telefone);
user.setRua(rua);
user.setBairro(bairro);
user.setCidade(cidade);
user.setEstado(estado);
PersistEngine.persist(user);
}
}
Header of file Jsp
with meta tag
:
"<"meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Does anyone know how I could solve?