JSTL之taglib

来源:互联网 发布:元和网络客服电话 编辑:程序博客网 时间:2024/05/01 02:32

一:需要的jar包

     (1)jstl.jar

     (2)standard.jar

 

二:web.xml需要配置

     <context-param>
                                    <description>resource for jstl fmt message taglib</description>
                                    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
                                    <param-value>messages</param-value>
   </context-param>

 

三:在jsp页面中需要如下使用:

     

<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<html>
  <head>
    <title><fmt:message key="product.name" /></title>
  </head>
 
  <body>
    This is my JSP page. <br>
  </body>
</html>

 

说明:<fmt:message key="product.name" />    里面的message为绑定资源的名称。

 

四:创建的资源文件为:

     (1) messages.properties

         里面的内容为:

                                  product.name         = 测试标题

     (2) messages_zh_CN.properties

           里面的内容为:

                                     product.name         = \u6D4B\u8BD5\u6807\u9898

 

原创粉丝点击