【问题标题】:struts to spring migration message resourcesstruts 到 spring 迁移消息资源
【发布时间】:2020-03-27 03:51:05
【问题描述】:

我正在将应用程序从 struts 1 转换为 Spring MVC,并且我试图弄清楚在我的 Java 代码中使用 import org.apache.struts.config.MessageResourcesConfig 和 org.apache.struts.util 时要做什么.MessageResources。在 spring-servlet.xml 文件中,我添加了包含我的消息资源属性文件的行,但我不再使用 struts 1 库。我将如何进行这部分代码的转换?

它在整个应用程序中被大量使用,例如这样的地方:

this.config = new MessageResourcesConfig();
 this.config.setParameter("path that was used here was set in the spring-servlet configuration file");
 this.resources = MessageResources.getMessageResources(this.config.getParameter());

【问题讨论】:

  • 我仍然无法弄清楚这一点,所以如果有人对此有任何见解,请告诉我。
  • 有人对这个问题有任何见解吗?
  • 仍然不知道该怎么办,有没有人有想法?

标签: java spring jsp web-applications struts


【解决方案1】:

我会重构您使用 java.util.ResourceBundle 加载资源的方式

// load resourcebundle.properties
bundle = ResourceBundle.getBundle("resourcebundle");

然后您可以使用

获取值
String val = bundle.getString(key);

你可以有一个帮助类来获取你需要的值,和/或找到一种方法将它传递给 JSP(不能帮助你,抱歉)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-18
    相关资源
    最近更新 更多