日期:2014-05-17  浏览次数:20737 次

struts2中自己定义的properties显示消息的资源文件,读不出里面的vaule值
struts2中自己定义的properties显示消息的资源文件,读不出里面的vaule值

我的properties文件时放在webinf下面的,所有配置都放在这里面,都在web.xml里面配置好了,怎么没用,用gettext方法取不出信息,用fielderror标签只是显示配置文件的key名字,不显示value值

web.xml的部分配置
<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
  org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
  </filter-class>
  <init-param> 
  <param-name>config</param-name> 
  <param-value>struts-default.xml,struts-plugin.xml,../config/struts/struts.xml</param-value> 
  </init-param> 
  </filter>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
 </listener>

struts.xml的部分配置
<constant name="spring.ObjectFactory" value="spring"></constant>
<constant name="struts.custom.i18n.resources" value="/WEB-INF/config/struts/messages-error"></constant>

messages-error.properties文件配置,用于显示消息
# roleProfile validation #
error.roleProfile.required=roleId is required.
error.module.required=moduleId is required.

existed.roleId=Role ID {0} has existed;

create.role=Create New Role {0}.
create.fail=Create New Role {0} Fail due to an exception with ticket number {1}.
create.successFully=Create New Role {0} Successfully.

delete.role=Roles {0} selected for deletion.
delete.fail=Roles {0} set for deletion fail.
delete.successFully=Roles {0} set for deletion successfully.

update.role=Start update Role {0}.
update.fail=Update Role {0} Fail due to an exception with ticket number {1}.
update.successFully=Update Role {0} Successfully.

action中的代码
public String saveRolePromfile() throws Exception {
moduleList=moduleBiz.getModule();
System.out.println(this.getText("existed.roleId", new String []{roleProfile.getRoleId()}));
if(roleProfile.getRoleId().trim().equals("") || roleProfile.getRoleId()=="")
{
this.addFieldError("error.roleProfile.required","error.roleProfile.required" );
return ERROR;
}
if(moduleId.trim().equals("") || moduleId=="")
{
this.addFieldError("error.module.required", "error.module.required");
return ERROR;
}
boolean flag= roleProfilebiz.getRoleProfileExist(roleProfile.getRoleId());
if(flag)
{
this.addFieldError("existed.roleId", 
this.getText("existed.roleId", new String []{roleProfile.getRoleId()}));
return ERROR;
}
System.out.println(moduleId);
String [] mid=moduleId.split(",");
List<RoleModule> roleModule=new ArrayList<RoleModule>();
for (int i = 0; i < mid.length; i++) {
RoleModule rm=new RoleModule();
rm.setModuleId(mid[i]);
roleModule.add(rm);
}
System.out.println(roleProfile.getRoleId());

System.out.println(roleProfile.getRoleId());
flag=roleProfilebiz.addRoleProfile(roleProfile, roleModule);
if(flag)
return SUCCESS;
else
return ERROR;

}

jsp页面的标签

<s:fielderror></s:fielderror>


标签只显示文件的key值
不知道为什么

------解决方案--------------------
Java code<