<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    blogjava's web log

    blogjava's web log
    ...

    Jstl 操作數(shù)據(jù)庫相關(guān)

    工作要找。。東西還是要學(xué)的。。。

    Code:
    JSTL SQL Query


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

    <sql:setDataSource?var="dataSource"?driver="org.gjt.mm.mysql.Driver"
    url="jdbc:mysql://localhost/forum?user=forumuser"
    scope="session"?/>

    <html>
    ??<head>
    ????<title>Query?Example</title>
    ??</head>

    ??<body>

    <sql:query?var?=?"users"?dataSource="${dataSource}">
    select?column_uid,column_pwd,column_accesses,column_first,column_last,column_bad,column_posted,column_type?from?t_users
    </sql:query>

    <table?border=1>
    <c:forEach?var="row"?items="${users.rows}">
    <tr>
    <td><c:out?value="${row.column_uid}"/></td>
    <td><c:out?value="${row.column_pwd}"/></td>
    <td><c:out?value="${row.column_accesses}"/></td>
    <td><c:out?value="${row.column_first}"/></td>
    <td><c:out?value="${row.column_last}"/></td>
    <td><c:out?value="${row.column_bad}"/></td>
    <td><c:out?value="${row.column_posted}"/></td>
    <td><c:out?value="${row.column_type}"/></td>
    </tr>
    </c:forEach>
    </table>


    ??</body>
    </html>

    JSTL SQL Update

    <%@?taglib?uri="http://java.sun.com/jstl/core"?prefix="c"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/core-rt"?prefix="c-rt"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/sql"?prefix="sql"?%>

    <sql:setDataSource?var="dataSource"?driver="org.gjt.mm.mysql.Driver"
    url="jdbc:mysql://localhost/forum?user=forumuser"
    scope="session"?/>

    <html>
    ??<head>
    ????<title>General?Query</title>
    ??</head>

    ??<body>
    ??<c:choose>
    ????<c:when?test="${param.cmd!=null}">
    ??????<c:set?var="str"?value="${param.cmd}"?/>
    ????</c:when>

    ????<c:otherwise>
    ??????<c:set?var="str"
    ??????value="select?*?from?tableName"?/>
    ????</c:otherwise>
    ??</c:choose>

    ??Please?enter?a?query:
    ??<br?/>

    ??<form?method="post">
    ????<textarea?name="cmd"?cols="40"?rows="5">
    <c:out?value="${str}"?/>
    ????</textarea>

    ????<br?/>

    ????<input?type="submit"?/>
    ??</form>

    ??<c:if?test="${pageContext.request.method=='POST'}">
    ????<c:catch?var="e">
    ??????<sql:query?var="users"?dataSource="${dataSource}"
    ??????sql="${param.cmd}"?/>

    ??????<table?border="1">
    ????????<c:forEach?var="row"?items="${users.rows}"
    ????????varStatus="status">
    ??????????<jsp:useBean?id="status"
    ??????????type="javax.servlet.jsp.jstl.core.LoopTagStatus"?/>

    ??????????<c-rt:if?test="<%=status.getCount()==1%>">
    ????????????<tr>
    ??????????????<c:forEach?var="col"?items="${row}">
    ????????????????<th>
    ??????????????????<c:out?value="${col.key}"?/>
    ????????????????</th>
    ??????????????</c:forEach>
    ????????????</tr>
    ??????????</c-rt:if>

    ??????????<tr>
    ????????????<c:forEach?var="col"?items="${row}">
    ??????????????<td>
    ????????????????<c:out?value="${col.value}"?/>
    ??????????????</td>
    ????????????</c:forEach>
    ??????????</tr>
    ????????</c:forEach>
    ??????</table>
    ????</c:catch>

    ????<c:if?test="${e!=null}">
    ??????<h3>Error</h3>

    ??????<c:out?value="${e}"?/>
    ????</c:if>
    ??</c:if>
    ??</body>
    </html>

    Updating a database using the sql:update tag

    //web.xml

    <?xml?version="1.0"?encoding="UTF-8"?>
    <!DOCTYPE?web-app?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN"
    ??"http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    ??<resource-ref>
    ????<res-ref-name>jdbc/address</res-ref-name>
    ????<res-type>javax.sql.DataSource</res-type>
    ????<res-auth>Container</res-auth>
    ??</resource-ref>
    </web-app>


    <%@?taglib?prefix="sql"?uri="http://java.sun.com/jstl/sql"?%>
    <%@?taglib?prefix="c"?uri="http://java.sun.com/jstl/core"?%>
    <html>
    <head>
    <title>Updating?a?database?using?the?sql:update?tag</title>
    <sql:setDataSource
    ??var="conn"
    ??dataSource="jdbc/address"
    />
    </head>
    <body>
    <h1>Modify?Address?List</h1>
    <sql:update?dataSource="${conn}"?var="addresses">
    ????INSERT?INTO?AddressList?(name,?street,?city,?country,?telephone)?VALUES?(?,??,??,??,??)
    ????<sql:param?value='${param["name"]}'/>
    ????<sql:param?value='${param["street"]}'/>
    ????<sql:param?value='${param["city"]}'/>
    ????<sql:param?value='${param["country"]}'/>
    ????<sql:param?value='${param["tel"]}'/>
    </sql:update>
    </body>
    </html>

    Presenting database content using tags

    //web.xml
    <?xml?version="1.0"?encoding="UTF-8"?>
    <!DOCTYPE?web-app?PUBLIC?"-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN"
    ??"http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    ??<resource-ref>
    ????<res-ref-name>jdbc/address</res-ref-name>
    ????<res-type>javax.sql.DataSource</res-type>
    ????<res-auth>Container</res-auth>
    ??</resource-ref>
    </web-app>




    <%@?taglib?prefix="sql"?uri="http://java.sun.com/jstl/sql"?%>
    <%@?taglib?prefix="c"?uri="http://java.sun.com/jstl/core"?%>
    <html>
    <head>
    <title>Presenting?database?content?using?tags</title>
    <sql:setDataSource
    ??dataSource="jdbc/address"
    ??var="conn"
    />
    </head>
    <body>

    <h1>Address?List</h1>
    <sql:query?dataSource="${conn}"?var="addresses">
    ????SELECT?*?FROM?AddressList
    </sql:query>
    <table?width="90%"?border="1">
    <tr>
    <!--?add?the?table?column?headings?-->
    <c:forEach?var="columnName"?items="${addresses.columnNames}">
    ??<th>?<c:out?value="${columnName}"/>?</th>
    </c:forEach>
    </tr>
    <!--?add?the?table?rows?from?the?result?set?-->
    <c:forEach?var="row"?items="${addresses.rowsByIndex}">
    ??<tr>
    ????<c:forEach?var="column"?items="${row}">
    ??????<td><c:out?value="${column}"/></td>
    ????</c:forEach>
    ??</tr>
    </c:forEach>
    </table>
    </body>
    </html>

    JSTL: Transaction with a JSP

    <%@?taglib?uri="http://java.sun.com/jstl/core"?prefix="c"?%>
    <%@?taglib?uri="http://java.sun.com/jstl/sql"?prefix="sql"?%>
    <html>
    <HEAD>
    ??????<TITLE>Using?a?Transaction?with?a?JSP</TITLE>
    ?????</HEAD>
    <body?bgcolor="white">
    ??????????<h2>View?table?Data</h2>
    <sql:transaction>??
    ??<sql:update>
    ??insert?into?atable?values(2,?'Joe','Id','Feb-24-1996','F')
    ??</sql:update>
    ????<sql:query?var="resultObj">
    ????select?*?from?atable
    ????</sql:query>

    </sql:transaction>??
    <table>
    <c:forEach?items="${resultObj.rows}"?var="row">
    ??<c:forEach?items="${row}"?var="column">
    ????<tr>
    ???<td?align="right">
    ?????<b><c:out?value="${column.key}"?/></b>
    ?????</td>
    ?????<td>
    ???????<c:out?value="${column.value}"?/>
    ?????</td></tr>
    ?????</c:forEach>
    ???????</c:forEach>
    ?????</table>
    </body>
    </html>



    SQL Tag Out Examples

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

    <sql:setDataSource?var="dataSource"?driver="sun.jdbc.odbc.JdbcOdbcDriver"?url="jdbc:odbc:forum"/>

    <html>
    ??<head>
    ????<title>SQL?Tag?Out?Examples</title>
    ??</head>

    ??<body>

    <sql:query?var?=?"users"?dataSource="${dataSource}">
    select?column_uid,column_pwd,column_accesses,column_first,column_last,column_bad,column_posted,column_type?from?t_users
    </sql:query>

    <table?border=1>
    <c:forEach?var="row"?items="${users.rows}">
    <tr>
    <td><c:out?value="${row.column_uid}"/></td>
    <td><c:out?value="${row.column_pwd}"/></td>
    <td><c:out?value="${row.column_accesses}"/></td>
    <td><c:out?value="${row.column_first}"/></td>
    <td><c:out?value="${row.column_last}"/></td>
    <td><c:out?value="${row.column_bad}"/></td>
    <td><c:out?value="${row.column_posted}"/></td>
    <td><c:out?value="${row.column_type}"/></td>
    </tr>
    </c:forEach>
    </table>


    ??</body>
    </html>

    詳細(xì)請看:http://www.java2s.com

    posted on 2006-06-15 19:27 record java and net 閱讀(1337) 評論(0)  編輯  收藏 所屬分類: Jsp&&Web

    導(dǎo)航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態(tài)語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 亚洲一级特黄特黄的大片| 亚洲国产精品一区二区三区在线观看 | 美女视频黄免费亚洲| 成人黄18免费视频| 四虎影视永久在线精品免费| 久久精品国产亚洲av成人| 青娱乐免费在线视频| 久青草国产免费观看| 久久国产亚洲精品无码| 国产小视频在线免费| 99热在线观看免费| 亚洲AV永久无码精品网站在线观看| 亚洲免费观看视频| 毛片免费观看网站| 永久免费A∨片在线观看| 亚洲欧美日韩中文字幕一区二区三区| 久久影院亚洲一区| 成年人网站在线免费观看| 中文在线免费看视频| 亚洲欧美日韩综合久久久久| 亚洲国产成人片在线观看| 精品免费久久久久久成人影院| a毛片在线还看免费网站| 亚洲精品女同中文字幕| 亚洲一区综合在线播放| 免费在线观看中文字幕| 免费观看国产网址你懂的| 香蕉免费看一区二区三区| 亚洲精品乱码久久久久蜜桃| 亚洲国产第一页www| 亚洲精品无码你懂的网站| 成年男女男精品免费视频网站| 久章草在线精品视频免费观看| 免费国产黄网站在线看| 亚洲卡一卡二卡乱码新区| 久久亚洲春色中文字幕久久久| 亚洲精品无码成人片在线观看| 毛片a级毛片免费播放下载| 在线免费观看亚洲| 日本人成在线视频免费播放| 久久久WWW免费人成精品|