Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > using .properties file in web app

Reply
Thread Tools

using .properties file in web app

 
 
harryos
Guest
Posts: n/a
 
      12-04-2008
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.

Can someone help me figure out how to correct this?

thanks
harry
 
Reply With Quote
 
 
 
 
Tom Anderson
Guest
Posts: n/a
 
      12-04-2008
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.

tom

--
I'm angry, but not Milk and Cheese angry. -- Mike Froggatt
 
Reply With Quote
 
 
 
 
Lew
Guest
Posts: n/a
 
      12-04-2008
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
 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      12-04-2008
On Thu, 4 Dec 2008, Lew wrote:

> 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.


Ah, i stand corrected.

Is the classpath controlled by entries in the WAR's manifest?

tom

--
I'm angry, but not Milk and Cheese angry. -- Mike Froggatt
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      12-04-2008
Lew wrote:
>> 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.



Tom Anderson <t...@urchin.earth.li> wrote:
> Ah, i stand corrected.
>
> Is the classpath controlled by entries in the WAR's manifest?


I don't believe so. According to my reading and experiments it
depends on which classloader you use. The standard is to look in
<app>/WEB-INF/classes/ for the root of classes and resources, and any
JARs in <app>/WEB-INF/lib/. The container classloader will also look
in <app>/. There are a couple of subtleties I don't remember offhand,
dependencies on whether you're using 'ServletContext#getResource
()' ('getResourceAsStream()') or the same-named methods from 'Class'
or 'ClassLoader'.

The Tomcat docs explain how there are multiple classloaders in that
product:
<http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html>

More full-blown Java EE containers like WebSphere or whatever have
even more sophisticated class-loading strategies.

--
Lew
 
Reply With Quote
 
harryos
Guest
Posts: n/a
 
      12-05-2008
On Dec 5, 12:34*am, Lew <l...@lewscanon.com> wrote:
> 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.


thanks for the replies,

I packed the include.properties file into WEB-INF/classes directory
using the following

<war....>
....
<zipfileset prefix ="WEB-INF/classes"
dir="${include.props.dir}" >
<include name="**/*.properties" />
</zipfileset>
</war>
Now the jsp can find the file using ResourceBundle.getBundle
("include")

Thanks again guys
harry
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to provide credentials to a web app from an external web app? rpfe@sapo.pt ASP .Net 1 02-09-2007 05:06 PM
convert java web app 2 .NET web app =?Utf-8?B?bml6YW0=?= ASP .Net 0 02-28-2006 04:46 AM
convert java web app 2 .NET web app =?Utf-8?B?bml6YW0=?= ASP .Net 0 02-28-2006 04:45 AM
403 Error Web App to Web App with Client Certificates Peter Sedman ASP .Net Security 18 11-18-2004 08:09 PM
How to secure one web app with another web app... Maras ASP .Net Security 0 06-17-2004 07:37 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57