日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

基于Session的国际化实现

發布時間:2024/6/21 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 基于Session的国际化实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

如何將我們網站的其它內容(如菜單、標題等)做國際化處理呢?這就是本篇要將的內容—>國際化。

在項目的spring.xml文件添加的內容如下

1 <mvc:interceptors> 2 <span style="white-space:pre"> </span><!-- 國際化操作攔截器 如果采用基于(請求/Session/Cookie)則必需配置 --> 3 <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> 4 </mvc:interceptors>

在項目中的源文件夾resources中添加myproperties.properties、myproperties_zh_.properties、myproperties_en_.properties三個文件

下面是jsp頁面的一些簡單信息如下,僅僅是演示沒考慮其他的:

1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 4 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 </head> 10 <% 11 Locale name = (Locale) session.getAttribute("i18nlanguage"); 12 ResourceBundle myResourcesBundle = ResourceBundle.getBundle("myproperties",name); 13 %> 14 <body> 15 <a href="${pageContext.request.contextPath}/index/findex.do?langType=en&page=Home">ENG</a> | 16 <a href="${pageContext.request.contextPath}/index/findex.do?langType=zh&page=Home"><%=myResourcesBundle.getString("simplified")%></a> 17 </body> 18 </html>

后臺Action層代碼如下:

1 package com.zhidao.oms.index; 2 3 import java.util.Locale; 4 5 import javax.servlet.http.HttpServletRequest; 6 7 import org.springframework.stereotype.Controller; 8 import org.springframework.web.bind.annotation.RequestMapping; 9 import org.springframework.web.bind.annotation.RequestParam; 10 11 @Controller 12 @RequestMapping("/index") 13 public class IndexAction { 14 15 16 @RequestMapping("/findex") 17 public String Findex(HttpServletRequest request,@RequestParam String langType,String page){ 18 19 if(langType.equals("zh")){ 20 Locale locale = new Locale("zh", "CN"); 21 request.getSession().setAttribute("i18nlanguage",locale); 22 } 23 else if(langType.equals("en")){ 24 Locale locale = new Locale("en", "US"); 25 request.getSession().setAttribute("i18nlanguage",locale); 26 }else{ 27 request.getSession().setAttribute("i18nlanguage",Locale.getDefault()); 28 } 29 return "/front/"+page+".jsp"; 30 } 31 32 }

有關的效果圖展示大家測試一下就好了!寫的不好的地方希望大家批評指正。

轉載于:https://www.cnblogs.com/jinwufeiyang/p/5823296.html

總結

以上是生活随笔為你收集整理的基于Session的国际化实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。