在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>

解决方案 »

  1.   

    我个人认为你的jstl标签可能出现了问题 只是之前遇到过这样的情况  但是不是用的jstl标签  所以具体夫的还得你自己去查看
      

  2.   

    <%
    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>以上只是一个小例子,亲可以自己参考改一下!接分
      

  3.   

    你在这句List<Sing> entities = nService.findNowPageInfo(nowPage);下面输出下entities的size,看看entities里有数据不。
      

  4.   

     <td><input type="text" name="id" value="entity.id"/></td>
    是不是应该这样写吖?没怎么用过jstl
      

  5.   

    很可能引入的<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>标签的地址不对
      

  6.   

    <%@ taglib prefix="c" uri="/WEB-INF/c.tld"%>
      

  7.   

    有两种可能:
    1> 要用doPost
    2>  <c:forEach var="entity" items="${entities }">貌似多一个空格。