protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); //... }
@WebServlet(name = "MyServlet", urlPatterns = {"/servlet"}) public class MyServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("UTF-8"); String param1 = request.getParameter("param1"); //... } }In this example, we set the character encoding to UTF-8 for the HTTP GET request and retrieve a parameter from the URL. The javax.servlet.http package library contains the HttpServletRequest class.