import java.util.Enumeration;
import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LocaleDisplay extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
//Get the client's Locales
Enumeration e = request.getLocales();
//Get the preferred Locale
Locale preferred = request.getLocale();
String prefDisplay = "";
if (preferred != null)
prefDisplay = preferred.getDisplayName();
//Display the preferred and any other locales
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
out.println("Locale Display");
out.println("Here is your Locale info...
");
out.println("Preferred Locale: ");
out.println(prefDisplay);
out.println("
");
out.println("Locale country: ");
if (preferred != null)
out.println(preferred.getDisplayCountry());
out.println("
");
out.println("Locale language: ");
if (preferred != null)
out.println(preferred.getDisplayLanguage());
out.println("
");
out.println("Lower priority Locales...
");
Locale loc = null;
while (e.hasMoreElements()) {
loc = (Locale) e.nextElement();
if (!(loc.getDisplayName().equals(prefDisplay))) {
out.println("Locale: ");
out.println(loc.getDisplayName());
out.println("
");
out.println("Locale country: ");
out.println(loc.getDisplayCountry());
out.println("
");
out.println("Locale language: ");
out.println(loc.getDisplayLanguage());
out.println("
");
}//if
}//while
out.println("");
} //end doGet
}