如何修改从 Applicationresources.properties 文件中获取值

发布于 2024-12-27 12:41:43 字数 421 浏览 5 评论 0原文

我正在开发一个简单的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初见 2025-01-03 12:41:43

我不确定您在何处以及如何定义 properties 文件,但是在搜索资源包时,struts2 以特定方式

  1. ActionClass.properties 搜索它们。
  2. BaseClass.properties(一直到 Object.properties)
  3. Interface.properties(每个接口和子接口)
  4. ModelDriven 的模型(如果实现 ModelDriven),对于模型对象,从 1 个
  5. package.properties(类所在目录的目录) 重复每个父目录一直到根目录)
  6. 搜索
  7. webwork.properties 中定义的 i18n 消息密钥层次结构本身的全局资源属性 (webwork.custom.i18n.resources)

有关详细信息,请参阅文档 /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 way

  1. ActionClass.properties.
  2. BaseClass.properties (all the way to Object.properties)
  3. Interface.properties (every interface and sub-interface)
  4. ModelDriven's model (if implements ModelDriven), for the model object repeat from 1
  5. package.properties (of the directory where class is located and every parent directory all the way to the root directory)
  6. search up the i18n message key hierarchy itself
  7. global resource properties (webwork.custom.i18n.resources) defined in webwork.properties

refer 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

俏︾媚 2025-01-03 12:41:43

将以下行添加到 struts.xml 文件中第一个包定义的顶部。

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

或者

在 src 文件夹中添加 struts.properties 文件。并将以下属性保留在其中。

struts.custom.i18n.resources=ApplicationResources

Add the below line in your struts.xml file just on top of the first package defintion.

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

OR

Add struts.properties file in your src folder. And keep the below property in it.

struts.custom.i18n.resources=ApplicationResources
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文