당사 웹 사이트의 다른 내용 (예 : 메뉴, 제목 등)을 국제화하는 방법은 무엇입니까? 이것이이 기사가 만들고 싶어하는 것입니다 -> 국제화입니다.
프로젝트의 Spring.xml 파일에 추가 된 내용은 다음과 같습니다.
<mvc : interceptors> <span style = "white space : pre"> </span> <!-국제 운영 인터셉터가 (요청/세션/쿠키)를 기반으로하는 경우 구성해야합니다-> <bean/> </mvc : interceptors>
프로젝트의 소스 폴더 리소스에 3 개의 파일을 추가하십시오 : myProperties.Properties, myProperties_ZH_.Properties 및 MyProperties_en_.properties
JSP 페이지에 대한 간단한 정보는 다음과 같습니다. 데모 및 다른 고려 사항은 없습니다.
<%@ page language = "java"contmenttype = "text/html; charset = utf-8"pageencoding = "utf-8"%> <! doctype html public "-// w3c // dtml 4.01 transitional // en" "http://www.w3.org/tr/tml/html 4/tml/html 4/tml 4.html/html 4.tml. <html> <head> <meta http-equiv = "content-type"content = "text/html; charset = utf-8"> <title> 여기에 제목 삽입 </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>배경 액션 레이어 코드는 다음과 같습니다.
패키지 com.zhidao.oms.index; java.util.locale import; import javax.servlet.http.httpservletrequest; org.springframework.stereotyp.controller import; org.springframework.web.bind.annotation.requestmapping; org.springframework.web.bind.annotation.requestparam; @controller @requestmapping ( "/index") public class indexaction {@requestmapping ( "/findex") public string findex (httpservletrequest request, @requestparam string langtype, 문자열 페이지) {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"; }}관련 렌더링을 테스트하십시오! 나는 모두가 내가 쓴 나쁜 것들을 비판하고 교정하기를 바랍니다.
세션을 기반으로하는 위의 국제화 방법은 편집자가 공유하는 모든 컨텐츠입니다. 나는 그것이 당신에게 참조를 줄 수 있기를 바랍니다. 그리고 당신이 wulin.com을 더 지원할 수 있기를 바랍니다.