基于Session的国际化实现
来源:互联网 发布:mysql区分32位和64位吗 编辑:程序博客网 时间:2024/06/02 01:18
如何将我们网站的其它内容(如菜单、标题等)做国际化处理呢?这就是本篇要将的内容—>国际化。
在项目的spring.xml文件添加的内容如下
<mvc:interceptors> <span style="white-space:pre"></span><!-- 国际化操作拦截器 如果采用基于(请求/Session/Cookie)则必需配置 --> <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> </mvc:interceptors>
在项目中的源文件夹resources中添加myproperties.properties、myproperties_zh_.properties、myproperties_en_.properties三个文件
下面是jsp页面的一些简单信息如下,仅仅是演示没考虑其他的:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><%Locale name = (Locale) session.getAttribute("i18nlanguage");ResourceBundle myResourcesBundle = ResourceBundle.getBundle("myproperties",name);%><body> <a href="${pageContext.request.contextPath}/index/findex.do?langType=en&page=Home">ENG</a> | <a href="${pageContext.request.contextPath}/index/findex.do?langType=zh&page=Home"><%=myResourcesBundle.getString("simplified")%></a></body></html>
后台Action层代码如下:
package com.zhidao.oms.index;import java.util.Locale;import javax.servlet.http.HttpServletRequest;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;@Controller@RequestMapping("/index")public class IndexAction {@RequestMapping("/findex")public String Findex(HttpServletRequest request,@RequestParam String langType,String page){if(langType.equals("zh")){ Locale locale = new Locale("zh", "CN"); request.getSession().setAttribute("i18nlanguage",locale); } else if(langType.equals("en")){ Locale locale = new Locale("en", "US"); request.getSession().setAttribute("i18nlanguage",locale); }else{ request.getSession().setAttribute("i18nlanguage",Locale.getDefault()); }return "/front/"+page+".jsp";}}
有关的效果图展示大家测试一下就好了!写的不好的地方希望大家批评指正。
1 0
- 基于Session的国际化实现
- 基于Session的国际化实现
- 基于session的springmvc国际化
- springMVC基于Session实现动态国际化
- 基于session的spring国际化配置
- springMVC 基于session的国际化配置
- Spring MVC国际化——基于Session的国际化
- Spirng 基于session国际化
- 基于HttpSession的国际化实现
- 基于HttpSession的国际化实现
- spring ApplicationContext.xml之基于Session的国际化配置初探
- 基于浏览器请求的国际化实现
- 基于浏览器请求的国际化实现
- SpringMVC基于浏览器国际化实现
- 基于浏览器和手动选择语言的国际化实现
- 基于jQuery.i18n.properties 实现前端页面的资源国际化
- springmvc国际化 基于请求的国际化配置
- 实现基于Memcache存储的Session类
- [leetcode]283. Move Zeroes
- 归并法
- Fractions to Decimals_usaco2.4.5_暴力
- Mac 常用命令
- 归并排序
- 基于Session的国际化实现
- JavaScript使用方式
- codeforces 601E. A Museum Robbery
- 理解Python中的装饰器
- 一招制敌 - 玩转 AngularJS 指令的 Scope (作用域)
- java web简单权限管理设计
- Android 混淆打包之类名指定
- ubuntu 中安装memcached
- 操作系统—内存管理