Java 在servlet中使用资源包?
我必须根据区域设置加载属性文件,我的servlet中有以下代码Java 在servlet中使用资源包?,java,jsp,servlets,internationalization,resourcebundle,Java,Jsp,Servlets,Internationalization,Resourcebundle,我必须根据区域设置加载属性文件,我的servlet中有以下代码 ResourceBundle contactBundle = ResourceBundle.getBundle("/popproperties/impprops", request.getLocale()); 我还在popproperties文件夹中创建了道具文件,如下所示 impprops_en_美国地产 以上代码工作正常,没有任何问题。我的问题是我只有一个porperties文件作为impprops_en_US.propert
ResourceBundle contactBundle = ResourceBundle.getBundle("/popproperties/impprops", request.getLocale());
我还在popproperties文件夹中创建了道具文件,如下所示
impprops_en_美国地产
以上代码工作正常,没有任何问题。我的问题是我只有一个porperties文件作为impprops_en_US.properties。如果用户将浏览器设置从US更改为其他语言环境,则没有其他相应语言环境的属性文件。在这种情况下,我仍然必须加载impprops_en_US.properties文件。我该怎么做?是否需要再创建一个属性文件作为impprops.properties
谢谢 这取决于您的代码,比如如果您在选择默认语言环境时得到null/default,那么您可以相应地进行检查并加载所需的语言环境。 对于前,在我的情况下:
String cc=req.getParameter("country");
String ln=req.getParameter("language");
Locale l=null;
if(cc==null)
l=new Locale("en","US");
else
l=new Locale(ln,cc);
ResourceBundle rb=ResourceBundle.getBundle("ApplicationResources",l);
req.setAttribute("resource", rb);
这取决于您的代码,比如如果您在选择默认语言环境时得到null/default,那么相应地,您可以进行检查并加载所需的语言环境。 对于前,在我的情况下:
String cc=req.getParameter("country");
String ln=req.getParameter("language");
Locale l=null;
if(cc==null)
l=new Locale("en","US");
else
l=new Locale(ln,cc);
ResourceBundle rb=ResourceBundle.getBundle("ApplicationResources",l);
req.setAttribute("resource", rb);
i18n的文档说明了什么?我猜它默认使用en_US,但我知道文档指定了行为。i18n的文档说了什么?我猜它默认使用en_US,但我知道文档指定了行为。