Internationalization of sessions:
How can we make other content (such as menus and titles) of our website internationalized? This is what we will discuss in this article-> internationalization.
Add the following content to the spring. xml file of the project:
1 <mvc:interceptors> 2 <span>3 <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /> 4 </mvc:interceptors>
Add the myproperties. properties, myproperties_zh _. properties, and myproperties_en _. properties files to the source folder resources of the project.
The following is some simple information about the jsp page, which is not considered in the Demonstration:
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
The code for the background Action layer is as follows:
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 }
Let's test the presentation! I hope everyone will criticize and correct the poor writing.