gpt4 book ai didi

properties - 从JSTL读取属性文件

转载 作者:行者123 更新时间:2023-12-04 13:29:24 25 4
gpt4 key购买 nike

我正在尝试使用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/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com