Demo.jsp
上传用户:liou020
上传日期:2017-07-13
资源大小:4458k
文件大小:3k
源码类别:

Applet

开发平台:

Java

  1. <%@ page import="javax.servlet.jsp.jstl.core.Config, java.util.*" %>
  2. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  3. <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
  4. <html>
  5. <head>
  6.   <title>JSTL: Formatting/I18N Support -- Demo Example</title>
  7. </head>
  8. <body bgcolor="#FFFFFF">
  9. <h3>Demo</h3>
  10. <p>
  11. The following bundles exist in the web application: 'Resources', 'Resources_de', 'Resources_fr', 'Resources_it'. 
  12. 'Resources' is the 'base' bundle and contains all messages in English. The italian bundle only holds one message
  13. (key=greetingMorning).
  14. </p>
  15. <c:if test="${!empty param.locale}">
  16.   <fmt:setLocale value="${param.locale}" scope="page"/>
  17. </c:if>
  18. <c:if test="${!empty param.fallback}">
  19.   <% Config.set(request, Config.FMT_FALLBACK_LOCALE, request.getParameter("fallback")); %>
  20. </c:if>
  21. <table>
  22. <tr>
  23.   <td><b>Set application-based locale:</b></td>
  24.   <td>
  25. <a href='?locale=fr&fallback=<c:out value="${param.fallback}"/>'>French</a> &#149;
  26. <a href='?locale=de&fallback=<c:out value="${param.fallback}"/>'>German</a> &#149;
  27. <a href='?locale=it&fallback=<c:out value="${param.fallback}"/>'>Italian</a> &#149;
  28. <a href='?locale=es&fallback=<c:out value="${param.fallback}"/>'>Spanish (no bundle)</a> &#149;
  29. <a href='?locale=&fallback=<c:out value="${param.fallback}"/>'>None</a>
  30.   </td>
  31. </tr>
  32. <tr>
  33.   <td align="right"><b>Set fallback locale:</b></td>
  34.   <td>
  35. <a href='?locale=<c:out value="${param.locale}"/>&fallback=fr'>French</a> &#149;
  36. <a href='?locale=<c:out value="${param.locale}"/>&fallback=de'>German</a> &#149;
  37. <a href='?locale=<c:out value="${param.locale}"/>&fallback=it'>Italian</a> &#149;
  38. <a href='?locale=<c:out value="${param.locale}"/>&fallback=es'>Spanish (no bundle)</a> &#149;
  39. <a href='?locale=<c:out value="${param.locale}"/>&fallback='>None</a>
  40.   </td>
  41. </table>
  42. <p>
  43. Request parameter "locale": <c:out value="${param.locale}"/><br>
  44. <i>(This value is used to set the application based locale for this example)</i>
  45. <p>
  46. Application based locale: <%=Config.find(pageContext, Config.FMT_LOCALE)%><br>
  47. <i>(javax.servlet.jsp.jstl.fmt.locale configuration setting)</i>
  48. <p>
  49. Browser-Based locales: 
  50. <% 
  51.   Enumeration e = request.getLocales();
  52.   while (e.hasMoreElements()) {
  53.     Locale locale = (Locale)e.nextElement();
  54.     out.print(locale);
  55.     out.print(" ");
  56.   }
  57. %>
  58. <br>
  59. <i>(ServletRequest.getLocales() on the incoming request)</i>
  60. <p>
  61. Fallback locale: <%=Config.find(pageContext, Config.FMT_FALLBACK_LOCALE)%><br>
  62. <i>(javax.servlet.jsp.jstl.fmt.fallbackLocale configuration setting)</i>
  63. <p>
  64. <jsp:useBean id="now" class="java.util.Date" />
  65. <h4>
  66. <fmt:formatDate value="${now}" dateStyle="full"/> &#149;
  67. <fmt:formatDate value="${now}" type="time"/>
  68. </h4>
  69. <p>
  70. <fmt:bundle basename="org.apache.taglibs.standard.examples.i18n.Resources">
  71. <table cellpadding="5" border="1">
  72.   <tr>
  73.     <th align="left">KEY</th>
  74.     <th align="left">VALUE</th>
  75.   </tr>
  76.   <tr>
  77.     <td>greetingMorning</td>
  78.     <td><fmt:message key="greetingMorning"/></td>
  79.   </tr>
  80.   <tr>
  81.     <td>greetingEvening</td>
  82.     <td><fmt:message key="greetingEvening"/></td>
  83.   </tr>
  84.   <tr>
  85.     <td>currentTime</td>
  86.     <td>
  87.       <fmt:message key="currentTime">
  88.         <fmt:param value="${now}"/>
  89.       </fmt:message>
  90.     </td>
  91.   </tr>
  92.   <tr>
  93.     <td>serverInfo</td>
  94.     <td><fmt:message key="serverInfo"/></td>
  95.   </tr>
  96.   <tr>
  97.     <td>undefinedKey</td>
  98.     <td><fmt:message key="undefinedKey"/></td>
  99.   </tr>
  100. </table>
  101. </fmt:bundle>
  102. <p>
  103. </body>
  104. </html>