jspページに表示されるjavaコードの国際化
プロジェクトはstruts 1の、1つの古いプロジェクトのコードで、1つのプレゼンテーションのプロジェクトをして、持ってきて使って、その中で国際化が必要で、struts 1の持参した国際化の策略でページの上のホームページの要素に対して解決しました.しかし、プロジェクトがきついため、多くの新しく追加された機能がjspページに追加され、jspページにはいくつかの<%...%>が現れた.その中のJavaコードはstruts 1が提供するメカニズムを利用して国際化することはできません.
次のクラスがあります.
コードに注釈がはっきりしています...しばらくしてから、祈りが読めるように...
小菜コミュニティ:http://www.itcaicai.com
次のクラスがあります.
- /**
- * jsp java
- */package com.platform.I18N;
- import java.util.MissingResourceException;
- import java.util.ResourceBundle;
- import javax.servlet.http.HttpServletRequest;
- import com.platform.common.PropertiesHelper;
- public class MessageResource {
- public static String getString(HttpServletRequest request, String file, String key){
- String ret = "";
- String prefix = "";
- // substring,
- String language = (String)request.getHeader("accept-language").substring(0,2);
- // ,
- PropertiesHelper helper = new PropertiesHelper();
- String resourceName = helper.getPropertise4FileNodename("MessageResource.properties", file);
- //
- if ("zh".equals(language)){
- prefix = "_zh_CN";
- }else if ("en".equals(language)){
- prefix = "_en_US";
- }
- //
- ResourceBundle Resource_Bundle = ResourceBundle.getBundle(resourceName+prefix);
- try{
- ret = Resource_Bundle.getString(key);
- }catch(MissingResourceException e){
- e.printStackTrace();
- }
- return ret;
- } }
コードに注釈がはっきりしています...しばらくしてから、祈りが読めるように...
小菜コミュニティ:http://www.itcaicai.com