{{{ #!html
JSP 支援多國語系
Tomcat + JSP + i18n + taglib
}}} [[PageOutline]] = 環境 = * sun java jdk 6 * tomcat 6 = 內容 = * web.xml (可參考附件) || 一般 || || || Eclipse || /WebContent/WEB-INF/web.xml || {{{ #!xml i18n index.html index.htm index.jsp http://jakarta.apache.org/taglibs/i18n-1.0 /WEB-INF/taglibs-i18n.tld }}} * index.jsp || 一般 || || || Eclipse || /WebContent/index.jsp || {{{ #!java <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.io.*,java.text.*,java.util.*,javax.servlet.jsp.*" %> <%@ taglib uri="http://jakarta.apache.org/taglibs/i18n-1.0" prefix="i18n" %> Examples of I18N Custom Tag Library Tag Usage This page displays all key/value pairs in the bundle. locale = <%= pageContext.getResponse().getLocale() %>
charset = <%= pageContext.getResponse().getCharacterEncoding() %>

WebApp translations

<% Locale locale = new Locale("zh",""); %>
1
2
}}} * taglibs-i18n.tld || 一般 || || || Eclipse || /WebContent/WEB-INF/taglibs-i18n.tld || [http://trac.nchc.org.tw/cloud/raw-attachment/wiki/waue/2010/0805/taglibs-i18n.tld (可下載附件)] * taglibs-i18n.jar || 一般 || || || Eclipse || /WebContent/WEB-INF/lib/taglibs-i18n.jar || [http://trac.nchc.org.tw/cloud/raw-attachment/wiki/waue/2010/0805/taglibs-i18n.jar (可下載附件)] * i18n_en.properties || 一般 || || || Eclipse || /Java Resource:src /org.mytest/ || {{{ #!text test1 = Hello world test2 = Now you can let jsp i18n using i18n taglib! }}} * i18n_zh_TW.properties || 一般 || || || Eclipse || /Java Resource:src /org.mytest/ || * utf8 轉碼工具 [http://www.tool.la/UTF-8/] {{{ #!text test1 = 你好!世界 test2 = 你現在已經能讓你的JSP使用I18N的taglib跟世界接軌囉! }}}