users.jsp
来自「this is for appfuse1.8 source using stru」· JSP 代码 · 共 142 行
JSP
142 行
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><%@ include file="/common/taglibs.jsp"%><html><head> <title>SQL Tags Example</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" media="all" href="<c:url value="/styles/default.css"/>" /> <script type="text/javascript" src="<c:url value="/scripts/global.js"/>"></script></head><body><div id="header"></div><c:import url="users-menu.jsp"/><div id="content"><h1>SQL Tags Example</h1><p>This page is designed to show how easy it is to list data from a databaseusing JSTL's SQL Tags. The following is the query that is used to expose a<em style="font-weight: bold">users</em> variable to the pageContext.</p><pre><sql:query var="users" dataSource="jdbc/appfuse"> select username, firstName, lastName from app_user order by upper(username);</sql:query></pre><p>Using the "View Table Source" link below this table, you can see the JSP/HTMLcode that's used to render this table.</p><sql:query var="users" dataSource="jdbc/appfuse"> select username, firstName, lastName from app_user order by upper(username);</sql:query><table class="list"><tr> <th><bean:message key="user.username"/></th> <th><bean:message key="user.firstName"/></th> <th><bean:message key="user.lastName"/></th></tr><c:forEach var="row" items="${users.rows}" varStatus="status"><c:choose><c:when test="${status.count % 2 == 0}"><tr class="even"></c:when><c:otherwise><tr class="odd"></c:otherwise></c:choose> <td><c:out value="${row.username}"/></td> <td><c:out value="${row.firstName}"/></td> <td><c:out value="${row.lastName}"/></td></tr></c:forEach></table><p style="margin-left: 10px"><a href="?" onclick="toggleDisplay('sqlSource'); return false"> View Table Source</a></p><div id="sqlSource" style="display:none; margin-left: 10px; margin-top: 0"><pre><table class="list"><tr> <th><bean:message key="user.username"/></th> <th><bean:message key="user.firstName"/></th> <th><bean:message key="user.lastName"/></th></tr><c:forEach var="row" items="${users.rows}" varStatus="status"><c:choose><c:when test="${status.count % 2 == 0}"><tr class="even"></c:when><c:otherwise><tr class="odd"></c:otherwise></c:choose> <td><c:out value="${row.username}"/></td> <td><c:out value="${row.firstName}"/></td> <td><c:out value="${row.lastName}"/></td></tr></c:forEach></table></pre></div><p>So that's cool, right? But how about something even better?! The <a href="http://displaytag.sf.net">display tag</a> <strong>now supports</strong>iterating this set of results. All you need to do is reference the ${users.row}in the <em>name</em> attribute when using the EL tag. Now you can render this same data set, but this time you get column sorting.</p><display:table name="${users.rows}" id="user" class="list"> <display:column property="username" sort="true" titleKey="user.username" headerClass="sortable"/> <display:column property="firstName" sort="true" titleKey="user.firstName" headerClass="sortable"/> <display:column property="lastName" sort="true" titleKey="user.lastName" headerClass="sortable"/></display:table><p style="margin-left: 10px"><a href="?" onclick="toggleDisplay('displaySource'); return false"> View Table Source</a></p><div id="displaySource" style="display: none; margin-left: 10px; margin-top: 0"><pre><display:table name="${users.rows}" id="user" class="list"> <display:column property="username" sort="true" titleKey="user.username" headerClass="sortable"/> <display:column property="firstName" sort="true" titleKey="user.firstName" headerClass="sortable"/> <display:column property="lastName" sort="true" titleKey="user.lastName" headerClass="sortable"/></display:table></pre></div><p>Heck, it even supports displaying all columns returned. If you use <code><display:table name="${users.rows}" class="list"/></code> - it'll render what you see below.</p><display:table name="${users.rows}" class="list"/><p>Now that you're into it - checkout the other examples I put together:</p><ul> <li><a href="users-edit.jsp">Editable Display Tag Table</a></li> <li><a href="users-edit-sql.jsp">Editable Table / SQL</a></li></ul></div><div id="footer">Suggestions or Questions should be addressed to <a href="mailto:displaytag-user@lists.sf.net">displaytag-user@lists.sf.net</a>.</div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?