ウェブサイトの他のコンテンツ(メニュー、タイトルなど)を国際化する方法は?これは、この記事が作成したいものです - >国際化。
プロジェクトのspring.xmlファイルに追加されたコンテンツは次のとおりです
<MVC:Interceptors> <Span Style = "White-Space:pre"> </span> <! - 国際操作インターセプターが(リクエスト/セッション/Cookie)に基づいている場合、構成する必要があります - > <bean/>> </mvc:インターセプター>
プロジェクトのソースフォルダーリソースに3つのファイルを追加します:myproperties.properties、myproperties_zh_.properties、myproperties_en_.properties
JSPページに関する簡単な情報、デモンストレーション、その他の考慮事項は次のとおりです。
<%@ page Language = "Java" contentType = "text/html; charset = utf-8" pageencoding = "utf-8"%> <! <html> <head> <メタhttp-equiv = "content-type" content = "text/html; charset = utf-8"> <title>ここにタイトル</title> </head> <%locale name =(locale)session.gettribute( "i18nonguage"); 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をインポートします。 javax.servlet.http.httpservletrequestをインポートします。 org.springframework.stereotype.controllerをインポートします。 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 local = new local 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をもっとサポートできることを願っています。