How to internationalize other contents of our website (such as menus, titles, etc.)? This is what this article wants to make -> Internationalization.
The content added in the spring.xml file of the project is as follows
<mvc:interceptors> <span style="white-space:pre"> </span><!-- If the international operation interceptor is based on (request/Session/Cookie), it must be configured --> <bean /> </mvc:interceptors>
Add three files in the source folder resources in the project: myproperties.properties, myproperties_zh_.properties, and myproperties_en_.properties
Here are some simple information about the jsp page, just the demonstration and no other considerations:
<%@ 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>The background Action layer code is as follows:
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"; } }Just test the relevant renderings! I hope everyone will criticize and correct the bad things I wrote.
The above internationalization method based on Session is all the content shared by the editor. I hope it can give you a reference and I hope you can support Wulin.com more.