如何在JSP页面中的表上显示数据库表 [英] How to display a database table on to the table in the JSP page

查看:63
本文介绍了如何在JSP页面中的表上显示数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 我的问题是我的数据库中的表无法显示在我的JSP页面中的表上.
  • 我发现此代码完全正确,但不知道您是否无法正确输出.
  • 请告诉我是什么问题.

  • My problem is that the table in my database is not able to be displayed at the table in my JSP page.
  • I find this code totally right but dont know y m not getting the output right.
  • Please tell me what is the problem.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"                                                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

</body>
<form method="post">

<table border="2">
<tr>
<td>ID</td>
<td>NAME</td>
<td>SKILL</td>
<td>ACTION</td>
</tr>
<%
try
{
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost/test";
String username="root";
String password="root";
String query="select * from jsp1";
Connection conn=DriverManager.getConnection(url,username,password);
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(query);
while(rs.next())
{

%>
    <tr><td><%rs.getInt("ID"); %></td></tr>
    <tr><td><%rs.getString("NAME"); %></td></tr>
    <tr><td><%rs.getString("SKILL"); %></td></tr>
        <%

}
%>
    </table>
    <%
    rs.close();
    stmt.close();
    conn.close();
    }
catch(Exception e)
{
    e.printStackTrace();
    }




%>

</form>
</html> 

推荐答案

这里的问题很简单.如果要在JSP中显示值,则必须使用<%=%>标记而不是<%%>,这是已解决的代码:

The problem here is very simple. If you want to display value in JSP, you have to use <%= %> tag instead of <% %>, here is the solved code:

<tr> <td><%=rs.getInt("ID") %></td> <td><%=rs.getString("NAME") %></td> <td><%=rs.getString("SKILL") %></td> </tr>

<tr> <td><%=rs.getInt("ID") %></td> <td><%=rs.getString("NAME") %></td> <td><%=rs.getString("SKILL") %></td> </tr>

这篇关于如何在JSP页面中的表上显示数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆