赞助商

MOST RECENT NEWS - WE MOMENTARILY RENEW

27
以前写的,现在转过来。(整合篇)

JSTL详解(一)


先来搭下环境,jstl的包当然是不能少的拉。其次,下载必须的标签库或者是java的标签库文件。没有的话,也可以联系我 xxx_programer@163.com
    将jstl 1.1.jar加到class中,(这就不要我详细的讲了吧),然后将标签库放到WEB-INF下或则将java的标签库文件(*.jar)放到WEB-INF\lib下,就可以写测试代码了。
    first_jstl.jsp

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
   <%@ page contentType="text/html; charset=gb2312" language="java" %>
   <c:set var="userName" value="hellking"/>
   <c:set value="16" var="age"/>
   欢迎您,<c:out value="${userName}"/><hr>
  <c:forEach var="i" begin="1" end="5">
  <font size=${i}>${i}</font>
  <br>
  </c:forEach>

  <c:if test="${age<18}">
   对不起,你的年龄过小,不能访问这个网页◎!
  </c:if>
  <br>
  </body>
  </html>

   web.xml
(使用java的标签库文件*.jar)
 
   <?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2_4.xsd"
   version="2.4">
 <display-name>jstl test</display-name>
 <description>
    jstl test
 </description>
</web-app>

(使用标签库文件*.tld)

 <?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
   version="2.4">

 <taglib>
   <taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
   <taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>

<taglib>
   <taglib-uri>http://java.sun.com/jstl/fmt-rt</taglib-uri>
   <taglib-location>/WEB-INF/fmt-rt.tld</taglib-location>
</taglib>

<taglib>
   <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
   <taglib-location>/WEB-INF/c.tld</taglib-location>
</taglib>

<taglib>
   <taglib-uri>http://java.sun.com/jstl/core-rt</taglib-uri>
   <taglib-location>/WEB-INF/c-rt.tld</taglib-location>
</taglib>

<taglib>
   <taglib-uri>http://java.sun.com/jstl/sql</taglib-uri>
   <taglib-location>/WEB-INF/sql.tld</taglib-location>
</taglib>

<taglib>
   <taglib-uri>http://java.sun.com/jstl/sql-rt</taglib-uri>
   <taglib-location>/WEB-INF/sql-rt.tld</taglib-location>
</taglib>

<taglib>
   <taglib-uri>http://java.sun.com/jstl/x</taglib-uri>
   <taglib-location>/WEB-INF/x.tld</taglib-location>
</taglib>

<taglib>
   <taglib-uri>http://java.sun.com/jstl/x-rt</taglib-uri>
   <taglib-location>/WEB-INF/x-rt.tld</taglib-location>
</taglib>
</web-app>

好了,一个最简单的包含有jstl的页面设计完成了。下面测试。
http://localhost:8080/jstl/frist_jstl.jsp
页面输出结果:

欢迎您,hellking


--------------------------------------------------------------------------------

1
2
3
4
5
对不起,你的年龄过小,不能访问这个网页◎!

呵呵。。。简单吧,下篇继续。。。。。:)

内文分页: [1] [2] [3] [4] [5] [6] [7]

作者:博爱老头@博爱老头的草屋
地址:http://www.icnote.com/post/16/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!

0 条评论 to “JSTL详解”

发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称  [注册]
密码  [游客无需密码]
网址
电邮
               

 

©2007-2012 IcNote.COM Theme by Youth work room