ajax讀取properties資源文件數(shù)據(jù)的方法
更新時間:2015年06月24日 17:24:08 作者:第2015換個昵稱
這篇文章主要介紹了ajax讀取properties資源文件數(shù)據(jù)的方法,實例分析了基于Ajax實現(xiàn)讀取properties資源文件數(shù)據(jù)的相關技巧,需要的朋友可以參考下
本文實例講述了ajax讀取properties資源文件數(shù)據(jù)的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
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(); //讀取資源文件數(shù)據(jù)拼接成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; }
注意:js請求成功后,如果其它js里也要用到讀出的內容,則把返回值賦給一個全局變量。
希望本文所述對大家的Ajax程序設計有所幫助。
您可能感興趣的文章:
- 詳解使用jquery.i18n.properties 實現(xiàn)web前端國際化
- 基于jQuery.i18n實現(xiàn)web前端的國際化
- java讀取properties配置文件的方法
- Java遍歷Properties所有元素的方法實例
- java獲取properties屬性文件示例
- Java讀取properties配置文件時,出現(xiàn)中文亂碼的解決方法
- 詳解五種方式讓你在java中讀取properties文件內容不再是難題
- Java中Properties的使用詳解
- java遍歷properties文件操作指南
- Java中的幾種讀取properties配置文件的方式
- 詳解使用jQuery.i18n.properties實現(xiàn)js國際化
相關文章
ajax實現(xiàn)文件異步上傳并回顯文件相關信息功能示例
這篇文章主要介紹了ajax實現(xiàn)文件異步上傳并回顯文件相關信息功能,結合實例形式分析了基于jQuery $.ajax方法的文件異步上傳以及后臺java程序對文件信息的讀取與顯示相關操作技巧,需要的朋友可以參考下2018-06-06