properties - 从JSTL读取属性文件

标签 properties jstl taglib

我正在尝试使用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即可。不需要做更多的事情了。

也可以看看:
  • Our JSTL wiki page


  • 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文件放在类路径的根目录中。

    也可以看看:
  • How to internationalize a Java web application?
  • 关于properties - 从JSTL读取属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4274765/

    相关文章:

    java - 在 JSP 日期格式化程序中处理不可解析的字符串

    java - JSTL 标签中的 Spring Security 开关盒

    objective-c - 使用点符号调用属性的 getter 方法

    properties - gradle属性信息

    html - 无法设置未定义的属性 'width'

    grails - TagLib输出错误的编码

    javascript - 如何使用 dojo 提交使用 spring 表单标签创建的表单

    c# - 有没有办法通过反射设置 C# 只读自动实现的属性?

    java - jSTL 不适用于 activiti 7 - 冲突库

    html - JSTL 在循环中每第 5 个字段集创建一个新行