You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by na...@lexmark.com on 2000/03/30 17:39:21 UTC
ResourceBundle.getBundle() throws MissingResourceException in JSP
When I try to get a ResourceBundle from a JSP, I get a MissingResourceException.
But if I do it in a Bean called from the JSP, it works. It also works from a
servlet. I have the properties file in the WEB-INF\classes directory. Anyone
know why? I think it has something to do with the ClassLoader. I'm using the
20000327 build of Tomcat
Nathan Klemperer
Here is the JSP file:
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<HTML>
<HEAD>
<TITLE>
Test
</TITLE>
</HEAD>
<%
try
{
out.println("<p>Try to get ResourceBundle from
ResourceBundle.getBundle()");
ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
out.println("<p>Success: " + rb.getString("helloworld.title"));
}
catch (MissingResourceException e)
{
out.println("<p>Failed: " + e);
}
try
{
out.println("<p>Try to get ResourceBundle from Bean");
ResourceBundle rb = new RB("LocalStrings").rb;
out.println("<p>Success: " + rb.getString("helloworld.title"));
}
catch (MissingResourceException e)
{
out.println("<p>Failed: " + e);
}
%>
Here is the Bean:
public class RB
{
public java.util.ResourceBundle rb;
public RB(String name)
{
rb = java.util.ResourceBundle.getBundle(name);
}
}