`

Spring mvc3自己手动写国际化

阅读更多

Spring3 MVC 中:如果使用国际化的形式,如果采用如下形式:

 

Java代码  收藏代码
sessionListener:
  1. @Override   
  2. public   void  sessionCreated(HttpSessionEvent se) {  
  3.     HttpSession session = se.getSession();  
  4.     String filePath = se.getSession().getServletContext().getRealPath("/" ) + FILE_NAME;  
  5.     Map<String, String> properties = readProperties(filePath);  
  6.     for  (String o : properties.keySet()) {  
  7.         session.setAttribute(o, properties.get(o));  
  8.     }  
  9. }  

 

 将国际化的内容加载到Session,如果按照以前的国家的内容方式:

 

Java代码  收藏代码
  1. site.name = 开发测试名称——Framewrok  
  2. site.copyright= XXXXX  

 的形式书写,在页面采用${site.name},${site.copyright}获取国际化的内容是拿不到的值得,原因是:Spring 3

 

采用的是Model 和ModelMap 的有限级别,session的优先级别最低,所以中间有“.”的时候,会在Model或ModelMap

中去寻找,没有寻找到,就认为是不存在,就不显示。为了避免如此我们应该用如下格式:

 

知识文档http://www.docin.com/p-221094007.html?locale=zh_CN收藏代码
分享到:
评论
1 楼 innger 2012-04-06  
为了避免如此我们应该用如下格式:
什么格式啊?

能不能在页面有 中文|English 让用户手动切换?

相关推荐

Global site tag (gtag.js) - Google Analytics