⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bundle.jsp

📁 JSP2.0实用教程实例源码
💻 JSP
字号:
<%@ page contentType="text/html;charset=GBk" import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
  <title>JSTL: Formatting/I18N</title>
</head>
<body>
<h3>JSTL: Formatting/I18N</h3>
<a href='?locale=zh'>中文</a> &#149;
<a href='?locale=en'>英文</a> &#149;
<a href='?locale=de'>德文</a> 
<p>
浏览器的locales: 
<% 
  Enumeration enum1 = request.getLocales();
  while (enum1.hasMoreElements()) {
    Locale locale = (Locale)enum1.nextElement();
    out.print(locale);
    out.print(" ");
  }
%>
<br/>
设置本地属性: <c:out value="${param.locale}"/><br>
<c:if test="${!empty param.locale}">
  <fmt:setLocale value="${param.locale}" scope="page"/>
</c:if>
<p>
<!-- 获取当前时间 -->
<jsp:useBean id="now" class="java.util.Date" />
<!-- 使用资源包 i18n.Resources -->
<fmt:bundle basename="i18n.Resources">
 <table cellpadding="5" border="1">
  <tr>
    <th align="left">键</th>
    <th align="left">值</th>
  </tr>
  <tr>
    <td>greetingMorning(资源包中已定义)</td>
    <td><fmt:message key="greetingMorning"/></td>
  </tr>
  <tr>
    <td>currentTime(传递参数)</td>
    <td>
      <fmt:message key="currentTime">
        <fmt:param value="${now}"/>
      </fmt:message>
    </td>
  </tr>
  <tr>
    <td>serverInfo(需要参数但未传递)</td>
    <td><fmt:message key="serverInfo"/></td>
  </tr>
  <tr>
    <td>undefinedKey(没有定义的键)</td>
    <td><fmt:message key="undefinedKey"/></td>
  </tr>
 </table>
</fmt:bundle>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -