E
E
Eugene2021-04-26 18:45:32
Java
Eugene, 2021-04-26 18:45:32

Krakozyabry instead of text ajax jquery and java servlet?

I send a JSON post request using Jquery, in a servlet I receive it using Gson with the line:

JsonObject data = new Gson().fromJson(request.getReader(), JsonObject.class);
String firstName= data.get("firstName").getAsString();
...

Instead of the Russian text - krakozyabry. In general, I then write this to a file, I thought there was a problem with it, but through the debugging mode I saw that the lines themselves turn out to be krakozyabry, that is, the firstName is already written wrong.

ajax request code:
let firstName = $("#ClientFirstNameForm").val();
        let lastName = $("#ClientLastNameForm").val();

        $.ajax({
            method: "POST",
            url: "/registerNewClient",
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            data:  JSON.stringify({"firstName" : firstName,
                "lastName" : lastName),
            dataType: 'json',

            success: function(data) {
                getClientList();
            },
            error: function(er) {
               
            }
        });
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question