FileDocCategorySizeDatePackage
LocaleDisplay.javaAPI DocExample2041Mon Feb 23 19:45:18 GMT 2004com.jspservletcookbook

LocaleDisplay

public class LocaleDisplay extends HttpServlet

Fields Summary
Constructors Summary
Methods Summary
public voiddoGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)

    
      //Get the client's Locales
     Enumeration enum = 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 (enum.hasMoreElements()){
	     loc = (Locale)enum.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>");