properties资源文件的内容如下:
hello=englishww name=english zk emailempty=field cannot be empty! emailinvalid=invalid email address!
js调用ajax处理代码:
$.ajax({ type:'post', datatype:'json', url:'/jeecms/jeecms/ajax/cms/getresourcebundle.do', async:false, success:function(data){ jsondata=data.jsi18n;//jsi18n是java返回时赋予的名称 jsi18n=eval_r('('+jsondata+')');//转化为json对象 alert(property is +jsi18n.hello); }, error:function(data){ alert(error); } });
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; }
相信看了本文案例你已经掌握了方法,更多精彩请关注其它相关文章!
推荐阅读:
jquery+与ajax怎么实现局部刷新功能
怎么使用ajax实现循环
以上就是ajax读取properties步骤详解的详细内容。
