0

I have a file named 'message.properties' placed on /src/main/resources and it works fine when I try to access its data on any .jsp file inside the /WEB-INF folder.

The thing is: I have a file (404.jsp) placed outside the /WEB-INF folder and I want to use the keys stored inside message.properties, but it cannot find them, giving me errors like "??? key.myKey ???

<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:messages" />
    <property name="defaultEncoding" value="UTF-8"/>
</bean>

How can I access the properties file from a file outside the /WEB-INF folder? I've tried changing the base name to "../resoruces/" or something like this, but couldn't solve the problem.

Again: it works fine for every file inside the WEB-INF folder, the issue is only with 404.jsp

Edit: I cannot solve it adding a scriptlet, because inside my 404.jsp I have some includes that need the same keys from message.properties

Gabriel R.
  • 303
  • 2
  • 15
  • This might be helpful: http://stackoverflow.com/questions/12686465/how-to-use-property-file-in-jsp – Rana_S Dec 09 '15 at 18:28
  • The pages in the WEB-INF folder are served from the `DispatcherServlet` the 404 knows nothing about such a thing and hence nothing about the spring based enhancements. Why don't you just move the 404 into the WEB-INF and let the `DispatcherServlet` handle it? – M. Deinum Dec 09 '15 at 18:48
  • @M.Deinum Well, I think the standard is to leave 404.jsp outside WEB-INF folder, since every time Spring fails to map a page it will fallback to 404.jsp... Is there any implication if I put it inside WEB-INF folder?! – Gabriel R. Dec 15 '15 at 15:03

1 Answers1

0

You can use a file for properties

FileInputStream fis = new FileInputStream("/your_path/test_properties.txt");
Properties prop = new Properties();
prop.load(fis);