例子中的一段代码看不懂,哪位高手给解释解释

zg 2003-08-19 03:20:04
这是一个servlet
public class HelloWorldExample extends HttpServlet {


public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("<html>");
out.println("<head>");

String title = rb.getString("helloworld.title");

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

// note that all links are created to be relative. this
// ensures that we can move the web application that this
// servlet belongs to to a different place in the url
// tree and not have any harmful side effects.

// XXX
// making these absolute till we work out the
// addition of a PathInfo issue

out.println("<a href=\"../helloworld.html\">");
out.println("<img src=\"../images/code.gif\" height=24 " +
"width=24 align=right border=0 alt=\"view code\"></a>");
out.println("<a href=\"../index.html\">");
out.println("<img src=\"../images/return.gif\" height=24 " +
"width=24 align=right border=0 alt=\"return\"></a>");
out.println("<h1>" + title + "aaa1</h1>");
out.println("</body>");
out.println("</html>");
}
}
...全文
26 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ryan76 2003-08-19
  • 打赏
  • 举报
回复
前面说了
返回你客户端首选的语言环境
例如zh-CN
zg 2003-08-19
  • 打赏
  • 举报
回复
感谢上面两位老大,问题解决了,原来目录下有个叫“LocalStrings.properties”的文件,那里定义了helloworld.title。
再问个问题,request.getLocale()返回的是什么??
zg 2003-08-19
  • 打赏
  • 举报
回复
再请问这个资源文件在哪里?我怎么能编辑它?现在这个例子运行的时候打出“HelloWorld!”,我要修改哪个文件,让结果打出“hello”
shine333 2003-08-19
  • 打赏
  • 举报
回复
ResourceBundle是专门用来国际化的,你只要把相关资源放到LocaleStrings_en.properties,LocaleStrings_fr.properties, _zh, _jp。。。。。就可以让你的程序在不同的地方说当地的话了,而且,以后只要修改.properties,基本不需要动你的程序了
bruni 2003-08-19
  • 打赏
  • 举报
回复
LocalStrings是一个properties资源文件的名字,或者含有表示locale的"LocalStrings_en".
helloworld.title是从资源文件中取得的.
里面有helloworld.title=HelloWorld!
zg 2003-08-19
  • 打赏
  • 举报
回复
我看不懂ResourceBundle rb =
ResourceBundle.getBundle("LocalStrings",request.getLocale());
这句是在干吗?
还有String title = rb.getString("helloworld.title");
返回到title中的字符串是“HelloWorld!”,可是整个页面并没有这个字符串,对象rb是从哪里取回这个字符串的??

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧