使用SQL数据库中的值过滤JSP上的表值
Filter table values on JSP with values from SQL database
我正在尝试制作一个基于servlet的应用程序,该应用程序从SQL数据库中获取值,并将其显示在JSP上动态创建的表中,该表已经在运行。下一步是创建某种过滤器,只显示其中一列中具有特定值的表行。我的想法是添加一个下拉菜单,并在"问题"列中选择包含该项目的行。我认为这有点直截了当。问题是,要在dropdowm菜单中填充的值在SQL数据库的表"Problem"中;并且它的每一行都具有id和name属性。目前,我正在尝试使用name
属性,并尝试将其与从我的查询(SQL Server 2008 R2)中获得的"Problem"列(
SELECT h.[name], c.[department], p.[name] AS problem, it.[name] AS interaction, ip.[title], ip.[date]
FROM [Database].[dbo].[Input] ip, [Database].[dbo].[Interaction] it, [Database].[dbo].[Problem] p, [Database].[dbo].[HelpdeskUser] h, [Database].[dbo].[Costumer] c
WHERE h.[id] = ip.[user_id]
AND it.[id] = ip.[interaction_id]
AND c.[id] = ip.[costumer_id]
AND p.[id] = ip.[problem_id]
ORDER BY date DESC";
),但是,很明显,我的头撞到墙上了,因为这不起作用。所以我想问你,你是否能以某种方式帮助我,如果我忽略了一些显而易见的东西,可以开启整个过程。
ViewInputServlet.java
public class ViewInputServlet extends GenericServlet {
public static final String PROBLEMS = "problems";
public static List<Problem> problems;
private void setProblems(HttpServletRequest req, HttpServletResponse resp) throws EmptyResultSetException {
Session session = HibernateUtilities.getSessionFactory().openSession();
if (ProblemDAO.hasRecords(session)) {
problems = ProblemDAO.selectProblems(session);
req.setAttribute(PROBLEMS, problems);
}
}
}
ViewInput.jsp
<% List<Problem> problems = (List<Problem>) request.getAttribute(ViewInputServlet.PROBLEMS); %>
<div class="innerField">
<table class="datatable" id="tableResults">
<thead>
<tr>
<th>NAME</th>
<th>DEPARTMENT</th>
<th>PROBLEM</th>
<th>TITLE</th>
<th>DATE</th>
</tr>
</thead>
<% for (Issue issue : (List<Issue>) request.getAttribute(ViewInputServlet.LIST)) {%>
<tr>
<td><%=issue.getName()%></td>
<td><%=issue.getDepartment()%></td>
<td id="prob_type"><%=issue.getProblem()%></td>
<td><%=issue.getTitle()%></td>
<td><%=issue.getDate()%></td>
</tr>
<%}%>
</table>
<div class="label">Show by Problems: </div>
<div class="field">
<div class="ui-widget">
<select name="<%=ViewInputServlet.PROBLEMS%>" id="chooseProblems">
<%if (problems != null) {
for (Problem problem : problems) {%>
<option value="<%=problem.getName()%>"><%=problem.getName()%></option>
<%}
}%>
</select> <input type="button" value="Reset" id="btn_reset" />
</div>
</div>
</div>
("问题"列是这里的关键:这是我想要过滤值的列,这就是为什么我在之前的一次尝试中给了它一个ID,但失败了)
函数.js
$("#chooseProblems").change(function () {
$("#tableResults").find("td").each(function () {
if ($(this).text !== $("#chooseProblems").val())
$(this).hide();
else
$(this).show();
});
});
如果你需要更多的信息或对我的推理有疑问,请询问:)
java脚本中的字符串比较是否存在问题。应该使用match方法而不是!==。
另外,当您说$(this).text或$(this).hide或$(this).show时,实际上您指的是行的列,而不是行。
相关文章:
- 有可能过滤来自嵌入式YouTube的声音吗
- 使用JSP从服务器检索和显示图像
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 为什么我的d3.jsselectAll+过滤器没有过滤
- servlet中的请求对象,而不是从jsp接收参数值
- 使用Javascript生成包含JSP的HTML
- 转义在jsp's脚本
- ui网格日期单元格过滤器,过滤日期格式导致显示错误的日期
- 显示&作为&在jsp中使用angularjs而不使用ng-bind-html
- Angular:使用选择列表选择过滤代码中的对象
- 在JSP中运行pdftk
- 使用javascript和jsp将数据插入到融合图中
- 如何将输入类型值或id从一个jsp传递到另一个jsp页面
- 在单击时过滤 JSON
- 如何在BookshelfJS中通过加入来过滤结果
- 在更改名称时,使用ajax jsp在下拉菜单中填充多个文件夹的数据
- 如何使用javascript过滤复杂的json对象
- 在使用cq:include包含外部JS之前,如何在JSP中包含全局JS变量
- 使用SQL数据库中的值过滤JSP上的表值
- 在 JavaScript 和 JSP 中过滤数据