How to make my java bean internationalization?

hi,

I have a project on tomcat. I have rewrite my jsp to multi-language according to user's browse language setting. User's language is English, the jsp shows them English. User's language is Chinese, the jsp shows them Chinese, and so on. But in my java bean code, some exception are thrown out with some message or alert. Can anybody tell me how to make these java beans show the language string acording to user's browse language setting?

thx

Pierre

[482 byte] By [pierre19458a] at [2007-10-1 19:43:21]
# 1

I am not sure that I interpret the question correctly, but since you say that

"some exception are thrown out with some message or alert" I am guessing that these are exceptions you are simply catching?

Here's a good explanation of how to create your own localized messages for such hardcoded exceptions:

http://www.ifi.uio.no/dok/java/tutorial/i18n/exception/hardcode.html

one_danea at 2007-7-11 16:03:08 > top of Java-index,Desktop,I18N...
# 2

Dear one_dane,

Thank you. That is a great document to me. The fact is that my owner code throws exception with a string. The code is:

if(amount<0) throw new Exception("Please input correct amount.");

If the code is in jsp, I can convert it to a internationalized String using struts tag <bean:message...>. But it is in a deep function of java class. So must I add a Locale object parameter to the function and all calling functions?

thx

yours,

Pierre

pierre19458a at 2007-7-11 16:03:08 > top of Java-index,Desktop,I18N...
# 3
Yes, you need to keep track of the session locale so that you can query it where neccessary.
one_danea at 2007-7-11 16:03:08 > top of Java-index,Desktop,I18N...