protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String charset = response.getCharacterEncoding(); if(charset != null) { System.out.println("Character encoding is: " + charset); } else { System.out.println("Character encoding is not specified."); } }
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.write("This is a response message with UTF-8 encoding."); }In this example, we are setting the character encoding of the response object to UTF-8 using the setCharacterEncoding() method, and then writing a response message to the client using the PrintWriter object. Package library: javax.servlet.http.