📄 users.jsp
字号:
<!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 database
using 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, first_name as firstName, last_name as 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/HTML
code that's used to render this table.
</p>
<sql:query var="users" dataSource="jdbc/appfuse">
select username, first_name as firstName, last_name as lastName
from app_user order by upper(username);
</sql:query>
<table class="list">
<tr>
<th><fmt:message key="userForm.username"/></th>
<th><fmt:message key="userForm.firstName"/></th>
<th><fmt:message key="userForm.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><fmt:message key="userForm.username"/></th>
<th><fmt:message key="userForm.firstName"/></th>
<th><fmt:message key="userForm.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="userForm.username" headerClass="sortable"/>
<display:column property="firstName" sort="true"
titleKey="userForm.firstName" headerClass="sortable"/>
<display:column property="lastName" sort="true"
titleKey="userForm.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="userForm.username" headerClass="sortable"/>
<display:column property="firstName" sort="true"
titleKey="userForm.firstName" headerClass="sortable"/>
<display:column property="lastName" sort="true"
titleKey="userForm.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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -