Struts2 从Struts 2中的操作类访问ApplicationResource.properties文件

Struts2 从Struts 2中的操作类访问ApplicationResource.properties文件,struts2,Struts2,我可以从Struts 2中的Action类访问ApplicationResource.properties文件密钥吗 并更新键的值?是,这是可能的。 假设您在applicationResources.properties文件中有属性error.login。 例如:错误。登录=无效的用户名/密码。请再试一次 然后在Action类中,您可以这样访问它:getText(“error.login”) 完整示例: applicationResources.properties LoginAction.ja

我可以从Struts 2中的Action类访问ApplicationResource.properties文件密钥吗 并更新键的值?

是,这是可能的。 假设您在applicationResources.properties文件中有属性error.login。 例如:错误。登录=无效的用户名/密码。请再试一次

然后在Action类中,您可以这样访问它:getText(“error.login”)

完整示例:

applicationResources.properties LoginAction.java
我认为您不能直接更新这些键的值,这有点违背了它作为(静态)资源的目的。
但是,您可以使用占位符

ApplicationResources.properties

property.key=Hi {0}, there's a problem with {1}
MyAction.java

public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             javax.servlet.ServletRequest request,
                             javax.servlet.ServletResponse response)
                      throws java.lang.Exception {
MessageResources msgResource = getResources(request);
String msg = msgResource.getMessage("property.key", "Sankar", "updating values in the resources.");
}
property.key=Hi {0}, there's a problem with {1}
public ActionForward execute(ActionMapping mapping,
                             ActionForm form,
                             javax.servlet.ServletRequest request,
                             javax.servlet.ServletResponse response)
                      throws java.lang.Exception {
MessageResources msgResource = getResources(request);
String msg = msgResource.getMessage("property.key", "Sankar", "updating values in the resources.");
}