您的位置:首页 > 编程语言 > Java开发

struts1练习时的报错

2014-03-29 22:31 218 查看
需求:

解决Cannot find message resources under key org.apache.struts.action.MESSAGE错误,今天在用struts1.3做一个注册页面时出现的错误。

 

前提条件:

struts-config.xml 存在如下配置:

  <!-- 消息文件 -->

  <message-resources parameter="application"/>

  <message-resources parameter="popedom"/>

 

JSP的调用方式:

System.out.println(TagUtils.getInstance().message(pageContext, "popedom", Globals.LOCALE_KEY, "username"));

 

出现问题:
老报异常:not find message resources under key popedom ...
 
解决办法:

struts-config.xml 增加配置:
  <!-- 消息文件 -->

  <message-resources parameter="applicationResources"></message-resources>
该设置最好放在:</action-mappings>"放到这里"</struts-config>;

确保ApplicationResources.properties文件在你建立的WEB-INF\classes文件夹中;

 
问题出现原因:
struts必须有一个不带key的资源文件,
若对 applicationresource.preperties 资源文件不指定 key 的话,JSP在通过 TagUtils 类指定的 Bundle 是“applicationresource”,而在 struts-config.xml 中的资源文件没有哪个的指定其key为“applicationresource”,最终导致出现异常

 

 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javaweb struts 异常