1

I'm new to JSP, trying to implement a Resource Bundle to put all the labels on my jsp page. Here's what I got.

I put this file labels.properties into WEB-INF/classes:

greeting=Hello!

And put this into my .jsp page:

<fmt:setBundle basename="labels" var="labels" scope="application"/>
<fmt:message key="greeting" bundle="${ labels }"/>

I see Hello! on the page, all is fine. But what if I want to put it into resources folder? Say I want this structure resources/bundles/labels.properties. I tried to change setBundle to this:

<fmt:setBundle basename="resources.bundles.labels" var="labels" scope="application"/>

But it didn't work. I also tried adding this to my web.xml which didn't help either:

<context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.bundles.labels</param-value>
</context-param>

I suppose I'm missing something. My resources folder is in Java Build Path but I still cannot hook any file from it as a resource bundle. Sorry if this is something easy and stupid, I really tried to find some solution to this here and on Google and what I posted above is all I've managed to come to :(

waterplea
  • 3,462
  • 5
  • 31
  • 47

2 Answers2

1

You say the resources folder is in build classpath, but what is required is that your building process puts it under /WEB-INF/classpath. When using maven, that means that you have that : /src/main/resources/resources/bundle.

Alternatively, but this would be a hardly portable solution, put your resources folder in classpath of the container (tomcat, jetty, or whatever you use ...)

Serge Ballesta
  • 143,923
  • 11
  • 122
  • 252
0

NO , you cant get the values outside the classpath.

Quoting from BalusC answer,

It has to go in the classpath. They're under the covers loaded by ResourceBundle which loads them by default form the classpath. So, putting it outside the classpath won't work. You can always put them in a (sub)package like so /WEB-INF/classes/local/filename.properties. You should then only access it with basename local.filename instead of filename.

So it is better to create a sub-folder in WEB-INF/classes. Read the Discussion here.

Learn More on using resource bundle through jstl

Community
  • 1
  • 1
Santhosh
  • 8,181
  • 4
  • 29
  • 56