This article mainly introduces the method of ajax reading property resource file data. The example analyzes the related skills of reading property resource file data based on Ajax. Friends in need can refer to the following
The example of this article is described Ajax method for reading properties resource file data. Share it with everyone for your reference. The specific implementation method is as follows:
The content of the properties resource file is as follows:
hello=englishww name=english zk emailEmpty=Field cannot be empty! emailInvalid=Invalid email address!
js calls ajax processing code:
$.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 processing file getResourceBundle.do code:
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; }
The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.
Related articles:
Comparative and detailed explanation of the use of various AJAX methods
Using the H5 feature FormData to upload files without refreshing
Realizing mobile phone positioning based on h5 ajax
The above is the detailed content of Ajax method to read properties resource file data. For more information, please follow other related articles on the PHP Chinese website!