JSTL-java ee5 tutorial

来源:互联网 发布:上海专业seo公司 编辑:程序博客网 时间:2024/05/17 07:53

JSTL includes a wide variety of tags that fit into discrete functional areas. To reflect this, as well as to give each area its own namespace, JSTL is exposed as multiple tag libraries. The URIs for the libraries are as follows:

  • Core: http://java.sun.com/jsp/jstl/core
  • XML: http://java.sun.com/jsp/jstl/xml
  • Internationalization: http://java.sun.com/jsp/jstl/fmt
  • SQL: http://java.sun.com/jsp/jstl/sql
  • Functions: http://java.sun.com/jsp/jstl/functions

the following table summarizes these functional areas along with the prefixes.

JSTL Tags 
Area
Subfunction
Prefix
Core
Variable support
c
Flow control
URL management
Miscellaneous
XML
Core
x
Flow control
Transformation
I18n
Locale
fmt
Message formatting
Number and date formatting
Database
SQL
sql
Functions
Collection length
fn
String manipulation

Thus, the tutorial references the JSTL core tags in JSP pages by using the following taglib directive:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" 
    prefix="c" %>

In addition to declaring the tag libraries, tutorial examples access the JSTL API and implementation. In the Application Server, the JSTL TLDs and libraries are distributed in the archive <J2EE_HOME>/lib/appserv-jstl.jar. This library is automatically loaded into the classpath of all web applications running on the Application Server, so you don't need to add it to your web application.

 
sql查询语句可以写为:
<sql:query var="books" sql="select * from web_bookstore_books where bookId='203'"></sql:query>

带参数:
<sql:query var="books" dataSource="jdbc/BookDB">
        select * from web_bookstore_books where bookId=? 
<sql:param value="${bid}"/>
</sql:query>
还有:
<sql:query var="books" sql="select * from web_bookstore_books where bookId = ?" >
       
<sql:param value="${bookId}" />
</sql:query>

数据库更新:
<sql:update var="books" sql="update web_bookstore_books set inventory = inventory - ? where bookId = ?" >
       
<sql:param value="${item.quantity}" />
       
<sql:param value="${bookId}" />
</sql:update>


注意配置文件:
<resource-ref>
        
<res-ref-name>jdbc/BookDB</res-ref-name>
        
<res-type>javax.sql.DataSource</res-type>
        
<res-auth>Container</res-auth>
        
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
原创粉丝点击