繁体   English   中英

如何过滤在JSP中使用表达式语言显示的表?

[英]How can I filter a table displayed using Expression Language in JSP?

这是我用来显示数据库中数据的代码。

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Book List</title>
</head>
<body>
    <sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver"
        url="jdbc:mysql://localhost:3306/BookTracker" user="root" password="school" />

    <sql:query dataSource="${snapshot}" var="result">
SELECT * from BookTrackerSystem;
</sql:query>

    <table border="1" width="100%">
        <tr>
            <th>Book ID</th>
            <th>Book Name</th>
            <th>Book Author</th>
            <th>Book Genre</th>
            <th>Book Description</th>
            <th>Book Due Date</th>
            <th>Book Status</th>
            <th>Full Name</th>
        </tr>
        <c:forEach var="row" items="${result.rows}">
            <tr>
                <td><c:out value="${row.id}" /></td>
                <td><c:out value="${row.bookName}" /></td>
                <td><c:out value="${row.bookAuthor}" /></td>
                <td><c:out value="${row.bookGenres}" /></td>
                <td><c:out value="${row.bookDesc}" /></td>
                <td><c:out value="${row.bookDueDate}" /></td>
                <td><c:out value="${row.bookStatus}" /></td>
                <td><c:out value="${row.fullname}" /></td>
            </tr>
        </c:forEach>
    </table>
</body>
</html>

我想要做的是,使用一个简单的文本框,我希望能够过滤使用上面的代码显示的表格,我相信我可以使用jQuery来做到这一点,但与Expression语言兼容的jQuery还是可以使用其他方法?的?

尽管事实上几乎没有人会支持您的工作:) ..我的意思是所有内容都在JSP中。

确切的答案如下:

  1. 添加带有文本框的html表单。

  2. 添加读取文本框值的代码作为request.getParameter()。 http://www.tutorialspoint.com/jsp/jsp_form_processing.htm

  3. 将(2)中的值添加到查询<sql:param value="..." />并添加where子句。 也许,在两种情况下,您将需要使用IF:a)过滤掉-没有文本值,并且在任何where没有b)过滤掉-文本值存在并且where使用。

不过,这将是服务器端的处理(过滤)。

如果要进行客户端筛选,请考虑使用DataTables http://www.datatables.net/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM