軟件開發人員應該學習更多的開發語言,我們要開發出適應各國的web應用程序,今天這篇文章是錯新技術頻道小編帶給大家的ResourceBundle類在jsp中的國際化實現方法,希望對你學習有幫助。
首先是兩個資源文件,分別為msg_en_US.properties和msg_zh_CN.properties
?
顯然中文字符是需要轉換過來的。
這是jsp頁面的代碼
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@page import="java.util.*"%><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>國際化</title> <style type="text/css"> div{ width: 300px; text-align: center; margin: 0 auto; } </style> </head> <body> <a href="/International/test.jsp?language=zh" rel="external nofollow" >簡體中文</a>|<a href="/International/test.jsp?language=en" rel="external nofollow" >English</a> <% ResourceBundle bund=ResourceBundle.getBundle("msg",request.getLocale()); String str=request.getParameter("language"); if(str!=null){ if("zh".equals(str)){ bund=ResourceBundle.getBundle("msg",Locale.CHINA); } else if("en".equals(str)){ bund=ResourceBundle.getBundle("msg",Locale.US); } } %> <div> <h1><%=bund.getString("inf") %></h1> <table> <tr> <td><%=bund.getString("name") %>:</td> <td><input type="text" name="name"/></td> </tr> <tr> <td><%=bund.getString("sex") %>:</td> <td><input type="text" name="sex"/></td> </tr> <tr> <td><%=bund.getString("age") %>:</td> <td><input type="text" name="age"/></td> </tr> <tr> <td><%=bund.getString("tel") %>:</td> <td><input type="text" name="tel"/></td> </tr> </table><br/> <input type="submit" value="<%=bund.getString("submit")%>" name="submit"/> </div> </body></html>
結果圖
?
以上這篇文章是錯新技術頻道小編帶給大家的ResourceBundle類在jsp中的國際化實現方法,我們都要趕上國際的潮流,飛往世界的頂端。
新聞熱點
疑難解答