如何修改从 Applicationresources.properties 文件中获取值
我正在开发一个简单的 GUI,我希望从 ApplicationResources.properties 文件中获取用户名值。 我的文件包含以下两行:
label.username= Username
label.password=Password
我正在使用包含 struts 2 标记的 JSP,其中包含以下代码片段:
<s:textfield cssClass="login-inp" name="username" key="label.username" size="20" />
但是当我运行我的项目时,我看到 label.username 表明未读取属性文件中的值。 我错过了什么吗?如何解决这个问题?请帮忙
提前致谢
I am developing a simple GUI in which i want username value to be fetched from ApplicationResources.properties file.
My file contains following two lines :
label.username= Username
label.password=Password
I am using JSP containing struts 2 tag contains following snippet :
<s:textfield cssClass="login-inp" name="username" key="label.username" size="20" />
But when i run my project i see label.username that indicates value from properties file is not read..
am i missing something ? How to solve this problem ? Kindly help
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定您在何处以及如何定义
properties
文件,但是在搜索资源包时,struts2 以特定方式有关详细信息,请参阅文档 /internationalization。
另外,Struts 2 key 属性可以在文本字段标签中使用,以指示框架对文本字段的名称和标签属性使用什么值。您可以只使用 key 属性,而不是直接提供这些属性及其值。
所以要么使用 name="username" key="label.username"。
只需浏览官方文档即可了解其工作原理以及框架如何搜索属性文件的详细信息
消息资源文件
I am not sure where and how you have defined the
properties
file but when searching for resource bundles struts2 search them in a specific wayrefer document for details /internationalization.
Additionally The Struts 2 key attribute can be used in the textfield tag to instruct the framework what value to use for the textfield's name and label attributes.Instead of providing those attributes and their values directly, you can just use the key attribute.
So either use name="username" key="label.username".
Just go through the official documents for details how this work and how framework search for the property files
message-resource-files
将以下行添加到 struts.xml 文件中第一个包定义的顶部。
或者
在 src 文件夹中添加 struts.properties 文件。并将以下属性保留在其中。
Add the below line in your struts.xml file just on top of the first package defintion.
OR
Add struts.properties file in your src folder. And keep the below property in it.