Need ResourceBundle Help.

S

Steve R. Burrus

I find myself in need right now of some help/assistance with using the
ResourceBundle class! You see, I am working on this particular servlet
called "WelcomeServlet.java". It is a relatively simple servlet which is
supposed to display a welcoming message in various languages. I chose to
work with the Spanish language for now. (es_ES) The resourceBundle is called
"WelcomeBundle_es_ES.java".

I am afraid that when I try to execute this servlet in my web browser all
that I seem to get is that server error message down below. Can someone
please help me with this?
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it
from fulfilling this request.

exception

java.util.MissingResourceException: Can't find bundle for base name
i18n.WelcomeBundle_es_ES.properties, locale en_US
java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:837)
java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:806)
java.util.ResourceBundle.getBundle(ResourceBundle.java:577)
WelcomeServlet.doGet(WelcomeServlet.java:18)
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache
Tomcat/5.5.7 logs.
 
T

Tor Iver Wilhelmsen

Steve R. Burrus said:
The resourceBundle is called "WelcomeBundle_es_ES.java".

No, it's not. The resourcebundle name should be "i18n.WelcomeBundle" -
the "_es_ES" part is what it looks for for a Spanish locale.

Can you post the code you use to get the ResourceBundle?
 
S

Steve R. Burrus

Yes, I will both post the code for this servlet > >" Can you post the code
you use to get the ResourceBundle?"<< AND also agree with you about the name
of the ResourceBundle. I have a particular book which says pretty much what
u said!

import java.util.ResourceBundle;
import javax.servlet.*;
import javax.servlet.http.*;

public class WelcomeServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
java.io.IOException {

//Get the client's Locale
Locale locale = request.getLocale();

ResourceBundle bundle = ResourceBundle.getBundle(
"i18n.WelcomeBundle_es_ES.properties",locale);

String welcome = bundle.getString("Welcome");


//Display the locale
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();

out.println("<html><head><title>"+welcome+"</title></head><body>");

out.println("<h2>"+welcome+"</h2>");

out.println("Locale: ");
out.println( locale.getLanguage()+"_"+locale.getCountry() );

out.println("</body></html>");
out.close();

} //end doGet

// doPost method ...

}//WelcomeServlet <<

And here is some "bonus" code for your inspection of the "WelcomeBundle"
file.

public class WelcomeBundle extends ListResourceBundle {

static final Object[][] contents = {

{"Welcome", "Hola y recepción, Bienvenidos"}
};

public Object[][] getContents() {
return contents;
}

}<<
 
S

Steve R. Burrus

Steve R. Burrus said:
Yes, I will both post the code for this servlet > >" Can you post the code
you use to get the ResourceBundle?"<< AND also agree with you about the
name of the ResourceBundle. I have a particular book which says pretty
much what u said!

import java.util.ResourceBundle;
import javax.servlet.*;
import javax.servlet.http.*;

public class WelcomeServlet extends HttpServlet {

public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
java.io.IOException {

//Get the client's Locale
Locale locale = request.getLocale();

ResourceBundle bundle = ResourceBundle.getBundle(
"i18n.WelcomeBundle_es_ES.properties",locale);

String welcome = bundle.getString("Welcome");


//Display the locale
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();

out.println("<html><head><title>"+welcome+"</title></head><body>");

out.println("<h2>"+welcome+"</h2>");

out.println("Locale: ");
out.println( locale.getLanguage()+"_"+locale.getCountry() );

out.println("</body></html>");
out.close();

} //end doGet

// doPost method ...

}//WelcomeServlet <<

And here is some "bonus" code for your inspection of the "WelcomeBundle"
file.

public class WelcomeBundle extends ListResourceBundle {

static final Object[][] contents = {

{"Welcome", "Hola y recepción, Bienvenidos"}
};

public Object[][] getContents() {
return contents;
}

}<<
 

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
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top