(二十九)JSP之国际化

 

 

 

 



  • 导入 <%@ taglib url="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
  • 创建三个语言配置文件,以guo.properties为基准

1 <body>
2     <fmt:setLocale value="en_us"/>    //强行将浏览器中的语言编码设置为ja
3      <fmt:bundle basename="guo" >
4         <fmt:message key="gretting"></fmt:message>
5     </fmt:bundle> 
6    <c:set var="price" value="1000"></c:set>
    <fmt:formatNumber type="currency" value="${price }"></fmt:formatNumber>
7 </body>

  结果:

 

 

  //basename="guo" 不能加扩展名,表示guo.properties为基准配置,<fmt:message key="gretting"> 表示输出key为gretting的值,如果此时浏览器的语言优先级

是中文的话,那么显示中文配置guo_zh.properties中的gretting的值,如果此时浏览器的语言优先级是日文的话,那么显示日文配置guo_ja.properties中的gretting的值.

 如果浏览器中是其他语言优先的话,则默认显示基准配置(guo.properties)中的key值。

 //<fmt:formatNumber type="currency" value="${price }"></fmt:formatNumber>  用于显示当前浏览器的语言地区的货币符号。如上图,<fmt:setLocale value="en_us"/>将语言编码强转为美国英文,所以货币为美元符。

 

 

1 <body>
2      <fmt:setLocale value="zh_CN"/>
3      <fmt:bundle basename="guo" >
4         <fmt:message key="gretting"></fmt:message>
5     </fmt:bundle> 
6 
7 <jsp:useBean id="now" class="java.util.Date"></jsp:useBean>
8 <fmt:formatDate value="${now}" />
9 </body>

结果:

  //<fmt:formatDate value="${now}" /> 将now对象用当前浏览器的语言地区的风格显示。

 


   jsp对数据库的操作(增删改查)

1     <sql:setDataSource driver="com.mysql.jdbc.Driver" password="" user="root" url="jdbc:mysql://127.0.0.1:3306/student" var="source" />
2 
3  <sql:update dataSource="${source}" sql="insert into student values('s005','123')"></sql:update>
4     
5     <sql:query var="rs" dataSource="${source}" sql="select * from student"></sql:query>
6     
7     <c:forEach items="${ rs.rows}" var="row" >
8         ${row.sno} <br/>
9      </c:forEach>

 

posted @ 2017-03-10 12:45  shyroke、  阅读(292)  评论(0编辑  收藏  举报
作者:shyroke 博客地址:http://www.cnblogs.com/shyroke/ 转载注明来源~