ResourceBundle

来源:百度知道 编辑:UC知道 时间:2024/06/20 12:59:11
程序代码:
public class RequestParamExample extends HttpServlet {

ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");

PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");

String title = rb.getString("requestparams.title");
out.println("<title>" + title + "</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");

// img stuff not req'd for source code html showing

ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
检查LocalStrings语言名称是否正确,符合I18N标准。另外,你是否有对应的资源文件xxx.properties,而且这个LocalStrings是一个完全限定类名,要与你的xxx对应。

ResourceBundle rb = ResourceBundle.getBundle("LocalStrings");
请检查资源文件名称是否正确,具体资料可以参考这个网址:
http://www.leftworld.net/online/j2sedoc/javaref/java.util.resourcebundle_dsc.htm