On Dec 4, 11:41*am, Tom Anderson <t...@urchin.earth.li> wrote:
> On Thu, 4 Dec 2008, harryos wrote:
> > i am trying to write a web app where a jsp page uses ResourceBundle to
> > get a property name and looks up its value from a include.properties
> > file.
>
> > include.properties
> > -------------------------
> > external-include=WEB-INF/jspf/header_tag.jsp
>
> > The main jsp contains
> > <html>
> > <% java.util.ResourceBundle bundle =
> > java.util.ResourceBundle.getBundle("include");
> > * * *String segment = bundle.getString("external-include");%>
> > <jsp:include page="<%=segment %>"/>
> > <body>
> > ...
> > </body>
> > </html>
>
> > I have put the include.properties in WEB-INF directory.
> > When i try to access the main jsp page ,I get this error=>
> > java.util.MissingResourceException: Can't find bundle for base name
> > include, locale en_US.
>
> Where exactly have you put the properties file? Resources need to be on
> your classpath. If your classpath is rooted in WEB-INF/classes, as is
> often the case, you need to put the properties file in there, rather than
> in WEB-INF itself.
The web-app classpaths is set by the container, and generally includes
the application root directory (the one above WEB-INF/) and WEB-INF/
classes/ both.
So it should be possible to refer to the properties file in WEB-INF/
as "WEB-INF/foo.properties", or whatever name. Possible, but not
actually correct.
Tom's advice is correct, because a properties file is used by the Java
classes, rather than by the display layer, so properly belongs in the
WEB-INF/classes/ rooted part of the classpath.
--
Lew
|