Error message returned by servlet: Error 500: Can't find bundle for base name Sample, locale en_US
 Technote (FAQ)
 
Problem
When developing servlets that read from a properties file in WebSphere® Application Server V4.0 using a ResourceBundle, it is necessary to follow the Locale-specific naming conventions for properties files.
 
Solution
Servlets that are developed to be deployed into WebSphere Application Server often use properties files that will also be included in the WAR file that is deployed. The ResourceBundle class simplifies accessing the contents of properties file, but it requires following Locale-specific (National Language Support enabled) naming rules. Otherwise, a 500 error might be returned by the servlet.

Example:
  1. Customer creates Sample.ear that contains a Web Module, Sample.

  2. The Sample Web Module has a single servlet, HelloWorld.class.

  3. The HelloWorld.class servlet opens the properties file, SampleData, that contains text to be displayed by the servlet.

  4. The operating system, in this case Windows® 2000, is configured for US English. This is locale en_US.

  5. If the properties file is named SampleData.properties, the following error is displayed in the output of the servlet:

    Error 500: Can't find bundle for base name Sample, locale en_US

  6. If the properties file is named SampleData_en_US.properties, then the properties file is opened correctly and the text of the property is retrieved and displayed by the servlet in the browser:

    Hello IBM Level Two Support

Note: You might have to restart the EAR file after you have made this correction.

Notes on using the Application Assembly Tool (AAT):
  • HelloWorld.class and HelloWorld.java are saved into the Web Module in the folder: Web Modules > Sample > Files > Class Files

  • The SampleData_en_US.properties file is added into the Web Module in the folder: Web Modules > Sample > Files > Resource Files

  • In both cases, you need to use AAT to select the directory for where the files are stored (in the Open dialog), then Add Files option to add the individual files. Ignore the "Files of type" entries, since you are going to select a "Root Directory", not a file.

  • The following should be defined, and in this order:
    1. New EAR file
    2. New Web Module in the EAR
    3. Define a context root for the Web Module (For example, /Sample)
    4. New Web Component for HelloWorld.class
    5. New Servlet Mapping for HelloWorld (For example, /hello)
    6. Add Class files (For example, HelloWorld.class)
    7. Add Resource file for your Locale (For example, en_US)

  • How to test: http://localhost/Sample/hello

Sample servlet code:

import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
import java.util.*;
import java.text.*;

// Constructor
public class HelloWorld extends javax.servlet.http.HttpServlet {
public HelloWorld2() {
   super();
}

// Service method: HTTP Get
public void doGet(HttpServletRequest req, HttpServletResponse res)
   throws ServletException, IOException {

   ResourceBundle messages =
      ResourceBundle.getBundle("SampleData");

   String property = messages.getString("text");

   res.setContentType("text/html");
   PrintWriter out = res.getWriter();
   out.println("<HTML>");
   out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
   out.println("<BODY>");

   if (null == property || "".equals(property)) {
      out.println("<BIG>Hello World </BIG>");
   }
   else {
      out.println("<BIG>Hello " + property + "</BIG>");
   }
   out.println("</BODY></HTML>");
}
}


Contents of SampleData_en_US.properties:

text=IBM Level Two Support
 
 
 


Document Information


Product categories: Software > Application Servers > Distributed Application & Web Servers > WebSphere Application Server > Deploy (for example: AAT or ANT or EAR/WAR/JAR)
Operating system(s): HP-UX
Software version: 4.0.1
Software edition:
Reference #: 1063591
IBM Group: Software Group
Modified date: Jan 17, 2005