在jsp页面上显示数据库里的信息

我想做一个查询
这个是我的处理查询的网页 网页运行没有问题 但是没有显示出想要的信息 用jsp写的

<%@pagelanguage="java"%>
<%@ page import = "java.util.*" %>
<%@page import="java.sql.*" %>
<%@ page import = "bookstore.*" %>
<%@page pageEncoding="UTF-8" %>
<html>
<head></head>
<body>
<h1><font size = "7" face="华文行楷">安格丽特的书架</font></h1>
<hr>
<h2>书籍查询结果页面</h2>
<h3>查询结果:</h3>
<%
Connection cnnn =Util.getConnection();
Statement stmt=cnnn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);

String tit =request.getParameter("title");
String id;
String author;
String pub;
String price;

String sqlstr="select id,title,author,pub,price from books where title='"+tit+"'";
stmt.executeQuery(sqlstr);
ResultSet rs=stmt.executeQuery(sqlstr);

while (rs.next()){
id=rs.getString("id");
tit=rs.getString("title");
author=rs.getString("author");
pub=rs.getString("pub");
price=rs.getString("price");
System.out.println(id+""+tit+""+author+""+pub+""+price);
}
cnnn.close();
%>
<a href="search.jsp"> 返回查询页面 </a>
<br>
<a href="index.jsp">返回主页</a>
</body>
</html>

这个试运行的结果

求指点 怎样才能让数据库里的信息显示出来

System.out.println(id+""+tit+""+author+""+pub+""+price);
是在控制台输出
你在页面应该使用<%=id%>则会在页面显示ID追问

是这样么  不过变成这样了...

追答



好久没有在页面写Java代码,好不习惯 应该是这样子的吧。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-01-13
参考一下:
//查询数据部分代码:

Connection conn = DBUtil.getConnection();
PreparedStatement pst = null;
ResultSet rs = null;
try{
String sql=“select emp_code, real_name from t_employee where organ_id=?”;
pst = conn.preparedStatement(sql);
pst.setString(1, “101”);
rs = pst.executeQuery();
List list = DBUtil. resultSetToList(ResultSet rs);
return list;
}finally{
DBUtil.close(rs, pst ,conn);
}

//JSP显示部分代码
<%
List empList = (List)request.getAttribute(“empList”);
if (empList == null) empList = Collections.EMPTY_LIST;
%>

<table cellspacing="0" width=”90%”>
<tr> <td>代码</td> <td>姓名</td> </tr>
<%
Map colMap;
for (int i=0; i< empList.size(); i++){
colMap = (Map) empList.get(i);
%>
<tr>
<td><%=colMap.get(“EMP_CODE”)%></td>
<td><%=colMap.get(“REAL_NAME”)%></td>
</tr>
<%
}// end for
%>
</table>本回答被网友采纳
相似回答