Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to check locale?

 
gino jersey
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your code loc is Locale type but you provide String to its equals(). So the equals() is always false.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think its not a JSP question. :roll:
[ October 27, 2005: Message edited by: Adeel Ansari ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic