This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes how to check locale? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how to check locale?" Watch "how to check locale?" New topic
Author

how to check locale?

gino jersey
Greenhorn

Joined: May 24, 2005
Posts: 21
Hi all- I'm dping something fairly simple but can;t get it to do what I want:

I need to check the locale and have it go to different bracnh of logic. I have:

<%
Locale loc = request.getLocale();
System.out.println("Locale: /" + loc );
System.out.println( loc.getLanguage()+"_"+loc.getCountry() );
%>
...

<%
if (loc.equals("ja")) {
.... // HERE FOR JA
}
else {
.... // ELSE LOGIC
}
%>

I need to check for japanese. The display shows "ja", and that's what I check for in my If statment , and yet when I check it still goes to the ELSE logic.
Am I checking for it incorrectly?
What's the proper way to check for locale values.
Thanks.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

You are comparing a Locale to a String. This comparison always returns false (you are lucky it doesn't throw an exception). If you want to know if the Locale's language is "ja" then do this:
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
In your code loc is Locale type but you provide String to its equals(). So the equals() is always false.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
I think its not a JSP question. :roll:
[ October 27, 2005: Message edited by: Adeel Ansari ]
 
Don't get me started about those stupid light bulbs.
 
subject: how to check locale?
 
Similar Threads
locale attribute in html:errors is not working
Calendar with Locale
setters and getters for field in customTag question
Localization / internationalization / TimeZone class
Internationalization / TimeZone / Locale / DisplayLanguage issue