JSTL Read Property File

I am trying to read the JSTL properties file form using taglib, but I cannot access it

<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%> 

I correctly found the tld file in the web.xml file, I am sure of this

<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/lib/fmt.tld</taglib-location>
</taglib>

The name of the properties file is msg. The properties

<fmt:bundle basename="msg">
<fmt:message key="error.more" />
</fmt:bundle>

I keep getting

???error.more???

instead of a message in the properties file

I think the problem is finding the properties file, or in the base name in

<fmt:bundle basename="msg">

where should I find the properties file and how can I make a link to it in the code

thanks everyone

+5
source share
5 answers
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%> 

This is the wrong URI. This is for the old JSTL 1.0, which does not work for a long time. For JSTL 1.1 you should use http://java.sun.com/jsp/jstl/fmt.


I correctly found the tld file in the web.xml file, I am sure of this

<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/lib/fmt.tld</taglib-location>
</taglib>

, URL- taglib. web.xml TLD. jstl.jar standard.jar /WEB-INF/lib. , JSTL 1.2, jstl-1.2.jar. .

. :


- msg.

<fmt:bundle basename="msg">
<fmt:message key="error.more" />
</fmt:bundle>

???error.more???

, , , <fmt:bundle basename="msg">, , ?

. msg msg.properties .

. :

+7

   < fmt:bundle basename="msg"/>
   < fmt:message key="error.more" />
+3

1), ? src. ,

Messages_en.properties

Messages_da.properties

,

com.isuru.test.i18N.resources

2) ?

<fmt:setLocale value="en" scope="session"/>
<fmt:bundle basename="com.isuru.test.i18N.resources.Messages" scope="session">
<fmt:message key="error.more" />

+2

, , .

: , , , , , :

com.test.clients   
com.test.stores 

- :

com.test.i18n 

other.test.i18n

error.more.properties
error.more_es_MX.properties

, :

<c:set var="language" value="${not empty param.language ? param.language : not empty language ? language : pageContext.request.locale}" scope="session" />
<fmt:setLocale value="${language}" />
<fmt:setBundle basename="com.example.i18n.text" />
<fmt:message key="error.more" />

, -.

- java - Java?

+1

, . messages_en.properties src/main/resources , . - , .

  • JSTL fmt uri jsp. <% @taglib prefix = "fmt" uri = "http://java.sun.com/jsp/jstl/fmt" % >

  • Refer to the package in jsp. <fmt: bundle basename = "messages_en">

  • Use the keys defined in the properties file. <fmt: message key = "error.loginfailure">
-1
source

All Articles