这次给大家带来ajax读取properties步骤详解,ajax读取properties的注意事项有哪些,下面就是实战案例,一起来看一下。
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; }
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
以上就是ajax读取properties步骤详解的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号