- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
想要一个如何在 jsp 中进行贪婪分页的工作示例。已经做了一些事情,但我的只显示 1 个结果。
jsp codes
<table id="menDisplayTable">
<tr id="menTr">
<c:forEach items="${returnedMenWatches}" var="proDetails">
<td id="menTd"><img src="data:image/jpg;base64,${proDetails.mode4}" height="50" width="50"/><br>
${proDetails.brand}<br>
${proDetails.name}<br>
${proDetails.gender}<br>
${proDetails.price}
</td>
</c:forEach>
</tr>
</table>
servlet codes
int page = 1;
int recordsPerPage = 10;
if(request.getParameter("page") !=null)
page = Integer.parseInt(request.getParameter("page"));
List<Product> returnedMenWatches = connect.getMenWatch();
int noOfRecords = connect.getNoOfRecords();
int noOfPages = (int) Math.ceil(noOfRecords * 1.0 / recordsPerPage);
request.setAttribute("returnedMenWatches", returnedMenWatches);
request.setAttribute("noOfPages", noOfPages);
request.setAttribute("currentPage", page);
request.getRequestDispatcher("men.jsp").forward(request, response);
DAO class
static int noOfRecords;
//method to display men products
public List<Product> getMenWatch() throws SQLException {
List<Product> returnedMenWatches = new ArrayList<Product>();
String male = "Male";
Statement myStatement = getConnection();
String query = "SELECT Product_ID, Brand, Product_Name, Gender, Product_Price, Product_Picture_Main, COUNT(Product_ID) AS NoOfRecords "
+ "FROM Products WHERE Gender = '"+male+"'";
rs = myStatement.executeQuery(query);
while (rs.next()){
Product proDetails = new Product();
proDetails.setProductId(rs.getInt("Product_ID"));
proDetails.setBrand(rs.getString("Brand"));
proDetails.setName(rs.getString("Product_Name"));
proDetails.setGender(rs.getString("Gender"));
proDetails.setPrice(rs.getFloat("Product_Price"));
Blob mode1 = rs.getBlob("Product_Picture_Main");
Blob mode2 = (Blob) mode1;
byte[]mode3 = mode2.getBytes(1, (int)mode2.length());
String mode4 = Base64.encode(mode3);
proDetails.setMode4(mode4);
noOfRecords = rs.getInt("NoOfRecords");
returnedMenWatches.add(proDetails);
}
return returnedMenWatches;
}
// method to get number of records returned from the get men watches query
public int getNoOfRecords() {
return noOfRecords;
}
请我需要你的帮助,提前致谢。进行了一些编辑,我添加了 sql 查询所在的 DAO 代码。
最佳答案
我认为你应该输入 <c:foreach....
之前<tr>
标记重复表行。
关于java - 如何使用 servlet 和 jSTL 在 jsp 中显示每页特定数量的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33413917/
我想要一个“常量”的 JSTL 文件并在其他文件中引用它们。 例如 常量.jsp: Audi 其他文件: I drive an ${car} which is ${colour} 上面的代码(
你能帮我把这个 JSTL 标签转换成 JSTL 三元吗 class="author" class="${page.class}" > 最佳答案 非常简单: 关于jSTL -
我需要根据请求中存在的值将单选按钮设置为选中状态。下面是我在 JSP 中使用的代码 checked"> Active checked">
我有这个,它正在工作: Hello, world! 我想把它改成这样:
这个问题已经有答案了: Evaluate empty or null JSTL c tags (8 个回答) 已关闭 6 年前。 例如 ${post.title} 最佳答案 使用空关键字
我是 Java EE 技术的初学者。我想知道 jSTL-api jar 和 jSTL-impl jar 之间有什么区别。 为什么API和实现是分开的?这是否意味着还有其他可用的实现? 最佳答案 API
我正在尝试在 jetty 中运行一个在 Tomcat 5.5 中运行良好的应用程序。该应用程序使用 servlet 2.4 和 JSP 2.0。 Jetty/Jasper 抛出这个异常: org.ap
所以这是我用来发送包含值 ${masession.idemp} 的参数“idemp”的代码 "> " alt="consulter tickets
这个问题在这里已经有了答案: How to install JSTL? The absolute uri: http://java.sun.com/jstl/core cannot be resol
我正在学习 Spring-MVC 教程,目前我在 part 2 上.本教程要求我下载 jSTL.jar 和 standard.jar,它们曾经是 Jakarta Taglibs 项目的一部分。该项目已
我正在尝试以这种特定格式格式化数字: “1 234.56” 所以,两个小数,用点分隔。并使用空格字符(可选单引号)将数千个分组。输入值永远不会大于 9999.99。 我尝试为此使用模式,甚至尝试使用语
我正在使用 fmt:formatNumber 在 JSTL 中格式化货币,它会以 ($100) 格式显示负货币,如何让它以负数格式显示负货币而不是 ($100)? 非常感谢, 起诉 最佳答案 如果您使
我不知道我做错了什么,但我不能包括 JSTL。我有 jSTL-1.2.jar,但不幸的是我得到了异常: org.apache.jasper.JasperException: The absolute
我只需要这样的东西: ..... function myFunc(param) { if(param == true) { return "aaa"
当我使用 JSTL c:forEach 标签时,我的项目出现以下错误。我正在使用 apache Tomcat v7.0。 我在 WEB-INF\lib 文件夹中添加了以下 jar。 taglibs-s
以下代码导致错误: 错误提示 "error a line 4: unknown symbol 'test'". 如何将 test 从 JSTL 代码传递到 JSP scriptlet? 最
我正在使用 JSF 2.0 (mojarra) + primefaces 开发 Web 应用程序。过去我成功地使用了jSTL库的[c:set]标签来存储一些临时数据或从其他标签中输出。 在我目前的情况
我的实际目标是得到 工作。我目前正在使用 jetty-runner 7.4.2 运行我的 Web 应用程序。作为一个随机的尝试,我下载了一个更新的版本。这样,当我尝试启动我的 Web 应用程序时,我
为了尝试使用 jSTL,我用 maven 安装了 jSTL 1.2 库。但是,当我通过此消息运行 jsp 页面时,“绝对 uri: [ http://java.sun.com/jsp/jstl/cor
当我混合 JSTL 1.0 和 JSTL 1.1 taglib 声明时,它会在我的一些服务器上导致 ParseException,但不是全部。 这是给我带来麻烦的代码块: |STRINGOFTEX
我是一名优秀的程序员,十分优秀!