<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ù)庫相關

    工作要找。。東西還是要學的。。。

    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>

    詳細請看:http://www.java2s.com

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

    導航

    常用鏈接

    留言簿(44)

    新聞檔案

    2.動態(tài)語言

    3.工具箱

    9.文檔教程

    友情鏈接

    搜索

    最新評論

    主站蜘蛛池模板: 日韩免费三级电影| 日韩高清在线高清免费| 久久亚洲国产伦理| 久久福利资源网站免费看| 亚洲国产精品久久久久秋霞小 | 免费国产叼嘿视频大全网站| 亚洲成人福利在线观看| 国产在线观看免费不卡| 中文字幕不卡免费视频| 亚洲无线一二三四区| 亚洲国产午夜中文字幕精品黄网站 | 久久国产精品萌白酱免费| 精品久久久久久亚洲精品| 亚洲乱码中文字幕综合234| 四虎最新永久免费视频| 色视频在线观看免费| 亚洲老熟女@TubeumTV| 亚洲?V无码乱码国产精品| 中文字幕免费高清视频| 免费人成在线观看播放a| 久久亚洲日韩看片无码| 亚洲第一页综合图片自拍| 久久免费的精品国产V∧| 免费国产a理论片| 亚洲制服在线观看| 77777亚洲午夜久久多人| 青青青国产免费一夜七次郎| 日本免费人成网ww555在线 | 国产精品怡红院永久免费| yy一级毛片免费视频| 亚洲日韩一区二区三区| 亚洲AV人无码激艳猛片| 国产特级淫片免费看| 亚洲一区免费视频| a级日本高清免费看| 国产午夜亚洲精品不卡免下载| 亚洲综合无码一区二区三区| 亚洲精品国产精品乱码不99| 国产在线播放免费| 免费网站看v片在线香蕉| 91福利免费视频|