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("<html><head><title>Locale Display</title></head><body>");
out.println("<h2>Here is your Locale info...</h2>");
out.println("<b>Preferred Locale:</b> ");
out.println(prefDisplay);
out.println("<br />");
out.println("Locale country: ");
if (preferred != null)
out.println(preferred.getDisplayCountry());
out.println("<br />");
out.println("Locale language: ");
if (preferred != null)
out.println(preferred.getDisplayLanguage());
out.println("<br /><br />");
out.println("<h3>Lower priority Locales...</h3>");
Locale loc = null;
while (e.hasMoreElements()) {
loc = (Locale) e.nextElement();
if (!(loc.getDisplayName().equals(prefDisplay))) {
out.println("Locale: ");
out.println(loc.getDisplayName());
out.println("<br />");
out.println("Locale country: ");
out.println(loc.getDisplayCountry());
out.println("<br />");
out.println("Locale language: ");
out.println(loc.getDisplayLanguage());
out.println("<br /><br />");
}//if
}//while
out.println("</body></html>");
} //end doGet
}
|