我正在尝试使用taglib读取JSTL中的“属性文件”,但是我无法访问它
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
我已经在web.xml中正确找到了tld文件,对此可以肯定。
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/lib/fmt.tld</taglib-location>
</taglib>
属性文件名为msg。特性
<fmt:bundle basename="msg">
<fmt:message key="error.more" />
</fmt:bundle>
我不断
???error.more???
而不是属性文件中的消息
我认为问题出在查找属性文件中,
或在基本名称中
<fmt:bundle basename="msg">
我应该在哪里找到属性文件,如何在代码中对其进行引用?
感谢大家
最佳答案
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt"%>
这是错误的URI。这适用于已久的旧JSTL 1.0。对于JSTL 1.1,您应该使用
http://java.sun.com/jsp/jstl/fmt
。I've located the tld file correctly in the web.xml , 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>
修复taglib URL时,这是不必要的。从您的
web.xml
中删除它,并删除所有那些松散的TLD文件。您应该只在jstl.jar
中添加standard.jar
和/WEB-INF/lib
。或者,当您使用JSTL 1.2时,只需jstl-1.2.jar
即可。不需要做更多的事情了。也可以看看:
The properties file name is msg. properties
<fmt:bundle basename="msg"> <fmt:message key="error.more" /> </fmt:bundle>
I keep getting
???error.more???
instead of the message in properties file I think the problem is either in locating the properties file , or in the base name in
<fmt:bundle basename="msg">
where should I locate the properties file, and how can I make a reference to it in the code?
将其放在类路径中。在您的特殊情况下,使用基本名称
msg
,您需要将msg.properties
文件放在类路径的根目录中。也可以看看:
关于properties - 从JSTL读取属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4274765/