从JSTL读取属性文件 [英] reading properties file from JSTL

查看:63
本文介绍了从JSTL读取属性文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用taglib从JSTL读取属性文件",但是我无法访问

I am trying to read a "properties file" form JSTL using taglib , but i can't access it

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

我已经在web.xml中正确找到了tld文件,对此很确定

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>

属性文件名为msg.属性

The properties file name is msg. properties

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

我不断得到

???error.more???

代替属性文件中的消息

我认为问题出在查找属性文件中, 或在

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??

谢谢大家

推荐答案

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

这是错误的URI.这适用于已久的旧JSTL 1.0.对于JSTL 1.1,您应该使用http://java.sun.com/jsp/jstl/fmt.

This is the wrong URI. This is for the old JSTL 1.0 which is out of life for long. For JSTL 1.1 you should be using http://java.sun.com/jsp/jstl/fmt.

我已经在web.xml中正确找到了tld文件,对此很确定

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文件.您应该在/WEB-INF/lib中仅包含jstl.jarstandard.jar.或者,当您使用JSTL 1.2时,只需jstl-1.2.jar.没什么需要做的.

This is unnecessary when you fix the taglib URL. Remove it from your web.xml and remove all those loose TLD files as well. You should just have jstl.jar and standard.jar in /WEB-INF/lib. Or when you're using JSTL 1.2, just the jstl-1.2.jar. Nothing more needs to be done.

属性文件名为msg.属性

The properties file name is msg. properties

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

我不断得到

???error.more???

而不是属性文件中的消息,我认为问题是在查找属性文件时出现,还是在<fmt:bundle basename="msg">中的基本名称中,我应该在哪里找到属性文件,以及如何在代码?

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

Put it in the classpath. In your particular case, with the base name msg, you need to put the msg.properties files in the root of the classpath.

这篇关于从JSTL读取属性文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆