Need help w. ResourceBundle

  • Thread starter Mr. Steve R. Burrus
  • Start date
M

Mr. Steve R. Burrus

Hi all, I am working on a simple "HelloWorldExample.java" servlet, and there
are 2 lines of code in it: "ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());",
and it compiles okay for me, but when I try to execute it in my browser, I
get all sorts of "MissingResourceExceptions" java exceptions!!

What could possibly be wrong anyway??? The "LocalStrings" mentioned as an
argument to the "getBundle" method are about 3 different languages, English,
French, and Spanish, and the whole servlet is designed to output a simple
greeting in those 3 languages. I of course checked the logs for the tomcat
server which I am using, but it really was of no help at all in trying to
figure out what is wrong. CaN someone please help me? I would greatly
appreciate it.
 
T

Tony Morris

Put the resource bundle (properties files?) on the classpath to be loaded as
a resource by the class loader.
For example, in the root of the war, or in WEB-INF/classes.
 
S

Steve R. Burrus

Tony said:
Put the resource bundle (properties files?) on the classpath to be loaded as
a resource by the class loader.
For example, in the root of the war, or in WEB-INF/classes.

Hi tony, yes they are properties files that I am trying/attempting to
work with okay! I did put them into the WEB-INF/classes folder in my
Tomcat installation, but alas, that didn't seem to help me at all!!
Incidentally, that is the very same folder that I have put the compiled
servlet class into FYI! Is there anyone else out there who can possibly
help me out of this "hopeless" situation that I seem to find myself in
right now??? No one besides tony has responded to me so far.
 
S

Sudsy

Mr. Steve R. Burrus said:
Hi all, I am working on a simple "HelloWorldExample.java" servlet, and there
are 2 lines of code in it: "ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());",
and it compiles okay for me, but when I try to execute it in my browser, I
get all sorts of "MissingResourceExceptions" java exceptions!!

You've given no information about the kind of servlet container
you use. Then there are the various configuration files...
Few of us are blessed with ESP so you'll have to provide more
detail if you want even an educated guess.
And don't be knocking Tony! Perhaps the reason that only one
person responded was that the rest of us had nothing to go on,
hence nothing to offer. At least Tony made an effort.
 
O

Oscar kind

Mr. Steve R. Burrus said:
Hi all, I am working on a simple "HelloWorldExample.java" servlet, and there
are 2 lines of code in it: "ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());",
and it compiles okay for me, but when I try to execute it in my browser, I
get all sorts of "MissingResourceExceptions" java exceptions!!

As specified in another post, you put the properties files in
WEB-INF/classes. This is good.

Now, assume the the ResourceBundle is called "LocalStrings", the Locale
specified is Dutch, and the default locale is US english. Then according
to the API, the code looks for the first of these files it can find:
- LocalStrings_nl_NL.propertyies
- LocalStrings_nl.properties
- LocalStrings_en_US.propertyies
- LocalStrings_en.properties
- LocalStrings.properties

Does either one of the files needed exist? Does the last one (always have
a default)?

If the file does exist, a MissingResourceException is thrown when a given
key doesn't exist. So that's a second place you may want to look.
 
S

Steve R. Burrus

Sudsy said:
You've given no information about the kind of servlet container
you use. Then there are the various configuration files...
Few of us are blessed with ESP so you'll have to provide more
detail if you want even an educated guess.
And don't be knocking Tony! Perhaps the reason that only one
person responded was that the rest of us had nothing to go on,
hence nothing to offer. At least Tony made an effort.

sudsy, i really don't wanna get into something of a "war of words" with
u, but actually far from me "knocking Tony" in my earlier post, I was
actually "knocking" all of the rest of you people for not yet responding
to my sincere posting!! If anything, I would praise Tony for being the
very first one to respond back to me!!
 
S

Sudsy

Steve R. Burrus wrote:
sudsy, i really don't wanna get into something of a "war of words" with
u, but actually far from me "knocking Tony" in my earlier post, I was
actually "knocking" all of the rest of you people for not yet responding
to my sincere posting!! If anything, I would praise Tony for being the
very first one to respond back to me!!

So could you provide the specifics of your installation?
 
M

Mr. Steve R. Burrus

Okay "Sudsy", here are the "specifics". I am trying to work in the Tomcat v.
5.0.27 servlet container, my particualar text editor that I am using is
TextPad. The version of the J2SDK that I am using is 1.5.0-beta 2, the
version of the J2SDKEE that I am using now is 1.4. I will even "throw in"
the fact that my OS platform is windows XP Home.
 
S

Sudsy

Mr. Steve R. Burrus said:
Okay "Sudsy", here are the "specifics". I am trying to work in the Tomcat v.
5.0.27 servlet container, my particualar text editor that I am using is
TextPad. The version of the J2SDK that I am using is 1.5.0-beta 2, the
version of the J2SDKEE that I am using now is 1.4. I will even "throw in"
the fact that my OS platform is windows XP Home.

I just took your two lines of code, plugged them into my Tomcat
framework and it worked just fine! No errors of any sort. Must
be a configuration problem.
Of course I had to incorporate them into a complete servlet,
importing the appropriate classes and extending HttpServlet. I
also had to modify the web.xml, create the WEB-INF/classes sub-
directory and create the properties file under the right name...
But your post mentioned none of that. So it begs the question:
have you gone through the complete process before?
Do you know how to identify the root context or define a new
one in the server.xml file? Are you familiar with the standard
naming and packaging conventions?
If you'd like, drop me an e-mail off-line and I'll send you the
complete war...
 
G

Guest

Hi all, I am working on a simple "HelloWorldExample.java" servlet, and
there are 2 lines of code in it: "ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());",
and it compiles okay for me, but when I try to execute it in my browser, I
get all sorts of "MissingResourceExceptions" java exceptions!!

What could possibly be wrong anyway??? The "LocalStrings" mentioned as
an
argument to the "getBundle" method are about 3 different languages,
English, French, and Spanish, and the whole servlet is designed to output
a simple greeting in those 3 languages. I of course checked the logs for
the tomcat server which I am using, but it really was of no help at all in
trying to figure out what is wrong. CaN someone please help me? I would
greatly appreciate it.

Check out the api for java.util.ResourceBundle:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/ResourceBundle.html

Look at getBundle() and getString() for a description of when these
methods throw a MissingResourceException.

HTH,
La'ie Techie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,000
Messages
2,570,252
Members
46,848
Latest member
CristineKo

Latest Threads

Top