struts多个properties,如何里面取值?

jiaminxy jiaminxy 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
现在有pro1.properties,pro2.properties,两个配置文件。
在Struts-config.xml里面
<message-resources key="pro1" parameter="pro1" />
<message-resources key="pro2" parameter="pro2" />

ActionForm.java
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {

ActionErrors errors = new ActionErrors();
if ((username == null) || (username.length() < 1)){
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.username.required"));
}

if ((password == null) || (password.length() < 1))
errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.password.required"));

return errors;

}

pro1.properties文件:
error.username.required = user
error.password.required = pass
运行时,报Cannot find message resources under key org.apache.struts.action.MESSAGE

我觉得原因是由于:errors返回时候没有指定相应的properties文件名。

请问该如何解决该问题,struts本身能解决不?
...全文
评论 5
收藏 已收藏
分享
返回顶部
jiaminxy
Java EE 67,535 成员 225,843 内容