时间:2021-07-01 10:21:17 帮助过:10人阅读
本文实例讲述了ajax读取properties资源文件数据的方法。分享给大家供大家参考。具体实现方法如下:
properties资源文件的内容如下:
hello=englishww name=english zk emailEmpty=Field cannot be empty! emailInvalid=Invalid email address!
js调用ajax处理代码:
java处理文件getResourceBundle.do代码:
publicString getResourceBundle(){
ResourceBundle RESOURCE_BUNDLE;
if(contextPvd.getSessionAttr("gLanguage")!=null&&contextPvd.getSessionAttr("gLanguage").equals("1")){
RESOURCE_BUNDLE=ResourceBundle.getBundle("jsI18n",Locale.ENGLISH);
}else{
RESOURCE_BUNDLE =ResourceBundle.getBundle("jsI18n",Locale.CHINA);
}//判断语言类别的,忽视
Set keySet=RESOURCE_BUNDLE.keySet();
//读取资源文件数据拼接成json格式字符串返回
String jsonString = newString();
jsonString+="{";
for(String key:keySet){
jsonString+='"'+key+'"'+":"+'"'+RESOURCE_BUNDLE.getString(key)+'"'+",";
}
//把字符串赋给返回对象的jsI18n(这里随意)
jsonRoot.put("jsI18n",jsonString.substring(0,jsonString.length()-1)+"}");
return SUCCESS;
}上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
各种AJAX方法的使用比较详解
利用H5特性FormData实现不刷新文件上传
基于h5 ajax实现手机定位
以上就是ajax读取properties资源文件数据的方法的详细内容,更多请关注Gxl网其它相关文章!