Using Resource Bundle Text on JSP Pages

To use the text defined in a resource bundle on your JSP pages:

  1. Open the JSP page you want to work on in the Visual Editor, such as edit.jsp.
  2. Add a jsp:usebean tag before the first heading. Enter myResources as the ID, and hr.MyResources as the Class. Set the Scope to session, and click OK.

    Note:

    If you do not compile the MyResources.java file till this point, then you will get an error symbol on the bean because the MyResources.class is not created till now. Open the MyResources.java file and compile it.

  3. Drag a jsp:scriptlet to the page, where you want the resource bundle text to be displayed, for example immediately next to the first heading.

    In the Insert Scriptlet dialog, enter the script for retrieving text from the resource bundle:

      out.println(myResources.getString("CompanyName") + ": " + 
      myResources.getString("SiteName"));
    
  4. Remove the original heading of the page, that is, AnyCo Corporation: HR Application.
  5. If you select the Source tab below the Visual Editor, you should see code for the page similar to the following:
     <jsp:useBean id="myResources" class="hr.MyResources" scope="session"/>    
         <h2 align="center">
         <%  out.println(myResources.getString("CompanyName") + ": " + 
             myResources.getString("SiteName"));%>
         </h2>
    
  6. To use resource bundle text as the label for a button, double-click the button in the Visual Editor. In the button properties dialog, for the Value parameter of the button, enter the following script:
    <% out.println(myResources.getString("UpdateButton"));%>
    
  7. If you view the Source code for the page, you will see code similar to the following:
    <input type="submit" 
      value=<% out.println(myResources.getString("UpdateButton"));%> />
    

If you now run your application, you will see the text you defined in your resource bundle displayed on the page.