在myEclipse中运行没有报错,分页也已经查询到数据库中的数据,但是页面不能显示数据,不知道什么原因……
运行页面:序号 歌曲名称 专辑名称 曲风类型 所属频道 歌曲地址 修改 删除 首页 上一页 下一页 末页
总记录数:21,总页数:2,当前页:1 页面代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title> starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
<!--
body {
background-color: #333333;
color:#828282;
}
-->
</style>
</head>
<body>
<a href="./admin/Songs inquires.jsp">歌手查询</a>|歌曲查询
<div align="center"><br><br>
<table border="1px">
<tr>
<td>序号</td>
<td>歌曲名称</td>
<td>专辑名称</td>
<td>曲风类型</td>
<td>所属频道</td>
<td>歌曲地址</td>
<td>修改</td>
<td>删除</td>
</tr>
<tbody>
<c:forEach var="entity" items="${entities }">
<tr>
<td><input type="text" name="id" value="${entity.id}"/></td>
<td><input type="text" name="singname" value="${entity.singname}"/></td>
<td><input type="text" name="style" value="${entity.style}"/></td>
<td><input type="text" name="album" value="${entity.album}"/></td>
<td><input type="text" name="channel" value="${entity.channel}"/></td>
<td><input type="text" name="url" value="${entity.url}"/></td>
<td><a href="${pageContext.request.contextPath}/updatesing.do?id=${entity.id}">修改</a></td>
<td><a href="${pageContext.request.contextPath}/deletesing.do?id=${entity.id}">删除</a></td>
</tr>
</c:forEach>
</tbody>
</table>
<div><jsp:include page="Songpage.jsp"></jsp:include></div>
</div>
</body>
</html>
Songpage.jsp分页代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<div>
<span><a href="${pageContext.request.contextPath}/listsing.do">首页</a></span>
<span><a href="${pageContext.request.contextPath}/listsing.do?nowPage=${nowPage-1}">上一页</a></span>
<span><a href="${pageContext.request.contextPath}/listsing.do?nowPage=${nowPage+1}">下一页</a></span>
<span><a href="${pageContext.request.contextPath}/listsing.do?nowPage=${countPage}">末页</a></span>
<br><span>总记录数:${countRecord},总页数:${countPage},当前页:${nowPage }</span>
</div>
servlet代码:
public class ListSingServlet extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String nPage = request.getParameter("nowPage");
int nowPage = 1; SingService nService = new SingServiceImpl(); // 总页数
int countRecord = nService.getCountRecord();
// 总记录数
int countPage = nService.getCountPage(); if ("".equals(nPage) || nPage == null) {
nowPage = 1;
} else {
nowPage = Integer.parseInt(nPage);
if (nowPage <= 1) {
nowPage = 1;
} if (nowPage >= countPage) {
nowPage = countPage;
}
} request.setAttribute("countRecord", countRecord);
request.setAttribute("countPage", countPage);
request.setAttribute("nowPage", nowPage); List<Sing> entities = nService.findNowPageInfo(nowPage); request.setAttribute("entities", entities); request.getRequestDispatcher("./admin/Songs inquires2.jsp")
.forward(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doGet(request, response);
}}
findNowPageInfo(nowPage)代码:
public List<Sing> findNowPageInfo(Integer nowpage) {
List<Sing> entities = new ArrayList<Sing>();
String sql = "select id,singname,style,album,channel,url from sing limit ?,?";
try {
conn = DBManager.getConnection();
pstmt = conn.prepareStatement(sql);
int index = 1;
pstmt.setObject(index++, (nowpage - 1) * this.PAGESIZE);
pstmt.setObject(index++, this.PAGESIZE); rs = pstmt.executeQuery();
while (rs.next()) {
Sing entity = new Sing();
entity.setId(rs.getInt("id"));
entity.setSingname(rs.getString("singname"));
entity.setStyle(rs.getString("style"));
entity.setAlbum(rs.getString("album"));
entity.setChannel(rs.getString("channel"));
entity.setUrl(rs.getString("url"));
entities.add(entity);
}
DBManager.release(conn, pstmt, rs);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return entities;
}public Integer getCountPage() {
return countPage;
}
xlm代码:
<servlet>
<servlet-name>ListSingServlet</servlet-name>
<servlet-class>hbsi.edu.com.servlet.ListSingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ListSingServlet</servlet-name>
<url-pattern>/listsing.do</url-pattern>
</servlet-mapping>
运行页面:序号 歌曲名称 专辑名称 曲风类型 所属频道 歌曲地址 修改 删除 首页 上一页 下一页 末页
总记录数:21,总页数:2,当前页:1 页面代码:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title> starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
<!--
body {
background-color: #333333;
color:#828282;
}
-->
</style>
</head>
<body>
<a href="./admin/Songs inquires.jsp">歌手查询</a>|歌曲查询
<div align="center"><br><br>
<table border="1px">
<tr>
<td>序号</td>
<td>歌曲名称</td>
<td>专辑名称</td>
<td>曲风类型</td>
<td>所属频道</td>
<td>歌曲地址</td>
<td>修改</td>
<td>删除</td>
</tr>
<tbody>
<c:forEach var="entity" items="${entities }">
<tr>
<td><input type="text" name="id" value="${entity.id}"/></td>
<td><input type="text" name="singname" value="${entity.singname}"/></td>
<td><input type="text" name="style" value="${entity.style}"/></td>
<td><input type="text" name="album" value="${entity.album}"/></td>
<td><input type="text" name="channel" value="${entity.channel}"/></td>
<td><input type="text" name="url" value="${entity.url}"/></td>
<td><a href="${pageContext.request.contextPath}/updatesing.do?id=${entity.id}">修改</a></td>
<td><a href="${pageContext.request.contextPath}/deletesing.do?id=${entity.id}">删除</a></td>
</tr>
</c:forEach>
</tbody>
</table>
<div><jsp:include page="Songpage.jsp"></jsp:include></div>
</div>
</body>
</html>
Songpage.jsp分页代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<div>
<span><a href="${pageContext.request.contextPath}/listsing.do">首页</a></span>
<span><a href="${pageContext.request.contextPath}/listsing.do?nowPage=${nowPage-1}">上一页</a></span>
<span><a href="${pageContext.request.contextPath}/listsing.do?nowPage=${nowPage+1}">下一页</a></span>
<span><a href="${pageContext.request.contextPath}/listsing.do?nowPage=${countPage}">末页</a></span>
<br><span>总记录数:${countRecord},总页数:${countPage},当前页:${nowPage }</span>
</div>
servlet代码:
public class ListSingServlet extends HttpServlet { /**
*
*/
private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { String nPage = request.getParameter("nowPage");
int nowPage = 1; SingService nService = new SingServiceImpl(); // 总页数
int countRecord = nService.getCountRecord();
// 总记录数
int countPage = nService.getCountPage(); if ("".equals(nPage) || nPage == null) {
nowPage = 1;
} else {
nowPage = Integer.parseInt(nPage);
if (nowPage <= 1) {
nowPage = 1;
} if (nowPage >= countPage) {
nowPage = countPage;
}
} request.setAttribute("countRecord", countRecord);
request.setAttribute("countPage", countPage);
request.setAttribute("nowPage", nowPage); List<Sing> entities = nService.findNowPageInfo(nowPage); request.setAttribute("entities", entities); request.getRequestDispatcher("./admin/Songs inquires2.jsp")
.forward(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { this.doGet(request, response);
}}
findNowPageInfo(nowPage)代码:
public List<Sing> findNowPageInfo(Integer nowpage) {
List<Sing> entities = new ArrayList<Sing>();
String sql = "select id,singname,style,album,channel,url from sing limit ?,?";
try {
conn = DBManager.getConnection();
pstmt = conn.prepareStatement(sql);
int index = 1;
pstmt.setObject(index++, (nowpage - 1) * this.PAGESIZE);
pstmt.setObject(index++, this.PAGESIZE); rs = pstmt.executeQuery();
while (rs.next()) {
Sing entity = new Sing();
entity.setId(rs.getInt("id"));
entity.setSingname(rs.getString("singname"));
entity.setStyle(rs.getString("style"));
entity.setAlbum(rs.getString("album"));
entity.setChannel(rs.getString("channel"));
entity.setUrl(rs.getString("url"));
entities.add(entity);
}
DBManager.release(conn, pstmt, rs);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return entities;
}public Integer getCountPage() {
return countPage;
}
xlm代码:
<servlet>
<servlet-name>ListSingServlet</servlet-name>
<servlet-class>hbsi.edu.com.servlet.ListSingServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ListSingServlet</servlet-name>
<url-pattern>/listsing.do</url-pattern>
</servlet-mapping>
解决方案 »
- java导出生成word文档问题!
- 女孩,如果不做软件了,做什么好?
- 刚从ASP转JSP公司内紧急任务求助
- jsp导出excel时因数据量过大乱码
- java程序里写的public void aa(){}方法 怎么在html页面上调用???????
- 一个struts的问题,请大家帮忙解决!!!
- 图片怎么转成BASE64上传? 或者说如何将上传流数据转Base64?
- jsp读入的ini配置文件应该放在什么地方,怎么读取?
- 请问大家做过B/S版本的电子白板吗,请给个思路!!
- 有关时间的显示????
- 求教!jsp+mysql,if (check=="t")判断语句无法正确判断字符
- jbpm能用jdbc吗
List result = 从数据库中查出来的集合
%>
<html>
<body>
<table>
<tr>
<td>序号</td>
</tr>
<!--循环输出开始-->
<%for(int i =0;i<result.size();i++){
<tr>
<td><%=i%></td>
</tr>
<%}%>
</table>
</body>
</html>以上只是一个小例子,亲可以自己参考改一下!接分
是不是应该这样写吖?没怎么用过jstl
1> 要用doPost
2> <c:forEach var="entity" items="${entities }">貌似多一个空格。