HttpServletRequest request = ... // obtain request object Locale defaultLocale = request.getLocale(); System.out.println("Default Locale: " + defaultLocale.toString());
HttpServletRequest request = ... // obtain request object Locale locale = request.getLocale(); ResourceBundle bundle = ResourceBundle.getBundle("Messages", locale); String greeting = bundle.getString("greeting"); response.getWriter().println(greeting);In this example, we obtain the Locale object of the client's preferred language and use it to load a resource bundle containing language-specific messages. We then retrieve a greeting message from the bundle and write it to the response. The `getLocale` method is part of the `javax.servlet.http` package which is part of the Java Servlet API.