日期:2014-05-17  浏览次数:20737 次

表格中的内容不显示 帮忙看下
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%@ page import="servlettest.*,servlettest.link.*"%>
<%
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> SsL is JSP 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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

  </head>
  
  <body>
  <%String sql="select userID from dl";
String mySqlDriver ="com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost:3306/test";;
Connection conn;
Class.forName(mySqlDriver).newInstance();
conn = DriverManager.getConnection(url,"root","123");
ResultSet rs=null;
Statement stmt=conn.createStatement();
if(conn==null){
System.out.println("get Conn Error");
}
rs=stmt.executeQuery(sql);
ResultSetMetaData rsmd = rs.getMetaData();
int numberOfColumns = rsmd.getColumnCount();
  %>
<center>
<%
out.println("数据库为:"+rsmd.getCatalogName(1));
%>
</center>
<table border>
<tbody>

<%
while(rs.next())

%>

<%
for (int j=1;j<numberOfColumns+1;j++){
 %>
 <tr>
 <td><%=out.print(j) %></td>
 </tr>
<%
for(int i=1;i<numberOfColumns+1;i++){
%>
<tr>
<td><%=rs.getString(i)%></td>
</tr>
<%
}
%>
<%
}
%>
<%
}
%>
</tbody>
</table>
<%
rs.close();
%>
  </body>
</html>


------解决方案--------------------
楼主 是 要 干 啥 ,确定 数据库 连接成功 ,还有
<%
while (rs.next()) {
%>

<%
for (int j = 1; j < numberOfColumns + 1; j++) {
%>
<tr>
<td><%=out.print(j)%></td>
</tr>
<%
for (int i = 1; i < numberOfColumns + 1; i++) {
%>
<tr>
<td><%=rs.getString(i)%></td>
</tr>
<%
}
%>
<%
}
%>
<%
}
%>




这个 地方 试试 这样 



<%
while (rs.next()) {
%>

<%
for (int j = 1; j < numberOfColumns + 1; j++) {
%>
<tr>
<td><%=out.print(j)%></td>

<td><%=rs.getString(j)%></td>
</tr>
<%
}
}
%>