I call the servlet from the form and try to print a line. Here is the code.

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.println("привет"); } 

Displays krakozyabry, what is the reason?

    1 answer 1

    First, there is a blunder: you forgot to close the stream.

     out.close(); 

    Secondly, for the absence of bad things there, it is necessary that the project encoding be in UTF-8 . There was a discussion about this. Next, look at what you have on the html-page. It should be like this:

     <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title></title> .... ... .. .. 

    Pay attention to <meta charset="utf-8" /> . Maybe this is not enough. All of my advice is enough for everything to work as it should for encoding.

    UPD1 :
    Yes, the idea still arrived. Here you only have the string "hello" on the page, absolutely without anything. Most likely, everything comes in the correct encoding, because there would be question marks instead of krakozyabr most likely. So in your browser, the default encoding is Windows and it could not recognize that it is a UTF-8 encoding. After all, only one line comes in Russian. There is nothing surprising. I am sure that if you write down everything you need for a full-fledged Internet page with the encoding indication, everything will work more than always.