之前我发过类似的帖子,大家觉得很麻烦,看的头都大了,这次发个简洁点的,呵呵 ,还请大家多帮帮忙啊,小弟不胜感激~~~~~~~~~~~~~~~~~~~~从search.html中输入查询内容
转到searchServlet中进行查询处理
最后转到result.jsp中输出查询结果数据库中有两个表,我上传了原数据库文件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. book表
name id author price typejava程序设计 11 陈凯歌 ¥44.00 3
C#入门与提高 22 李建国 ¥23.00 3
高等数学 33 王文飞 ¥30.00 2
中国的复兴 44 方见 ¥30.00 1
现代武器介绍 55 懂华 ¥56.00 4
数据结构 66 李丽丽 ¥48.00 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~2. booktype表
typeid typename
1 社会
2 数学
3 计算机
4 军事
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
searchServlet负责连接数据库,查询数据,并且将结果传到result.jsp中;
我的查询语句sql为select * from book,booktype where book.type=booktype.typeid and typename='"+search+"'
search 为要查询的书的类别。在searchServlet中将符合条件的每本书的信息存在boobbean对象中,再将每一个bookbean对象存在list中,
之前创建了 Vector list=new Vector(); while(rs.next()){
bookbean book=new bookbean();
book.setName(rs.getString("name"));
//out.println(rs.getString("name"));
book.setId(rs.getString("id"));
book.setAuthor(rs.getString("author"));
book.setPrice(rs.getString("price"));
book.setTyep(rs.getString("typename"));
list.add(book); }最后通过session吧list传到result.jsp中, session.setAttribute("list", list); response.sendRedirect("result.jsp");~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在result.jsp中将存在session中的list取出来,并将里面的bookbean对象的所有信息逐个输出首项获得list: Vector list=(Vector)session.getAttribute("list"); bookbean book=new bookbean();然后输出:
for(int i=0;i<list.size();i++){
book=(bookbean)list.get(i);
out.print("<tr>");
out.print("<td>");out.print(book.getName());out.print("</td>");
out.print("<td>");out.print(book.getId());out.print("</td>");
out.print("<td>");out.print(book.getAuthor());out.print("</td>");
out.print("<td>");out.print(book.getPrice());out.print("</td>");
out.print("<td>");out.print(book.getType());out.print("</td>");
out.print("</tr>");
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
基本上就是上面的过程,运行没有错误,tomcat也没有出现错误,可就是不显示查询的结果
只有
我测试了一下,去掉关于Vector 的所有内容,session中只存一个bookbean对象,result也只该bookbean的所有信息
,结果正确~~~~~~~~~~~~~~~~~,我很费解,研究了好长时间,仍然不行,还请高手指点一下。
转到searchServlet中进行查询处理
最后转到result.jsp中输出查询结果数据库中有两个表,我上传了原数据库文件
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. book表
name id author price typejava程序设计 11 陈凯歌 ¥44.00 3
C#入门与提高 22 李建国 ¥23.00 3
高等数学 33 王文飞 ¥30.00 2
中国的复兴 44 方见 ¥30.00 1
现代武器介绍 55 懂华 ¥56.00 4
数据结构 66 李丽丽 ¥48.00 3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~2. booktype表
typeid typename
1 社会
2 数学
3 计算机
4 军事
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
searchServlet负责连接数据库,查询数据,并且将结果传到result.jsp中;
我的查询语句sql为select * from book,booktype where book.type=booktype.typeid and typename='"+search+"'
search 为要查询的书的类别。在searchServlet中将符合条件的每本书的信息存在boobbean对象中,再将每一个bookbean对象存在list中,
之前创建了 Vector list=new Vector(); while(rs.next()){
bookbean book=new bookbean();
book.setName(rs.getString("name"));
//out.println(rs.getString("name"));
book.setId(rs.getString("id"));
book.setAuthor(rs.getString("author"));
book.setPrice(rs.getString("price"));
book.setTyep(rs.getString("typename"));
list.add(book); }最后通过session吧list传到result.jsp中, session.setAttribute("list", list); response.sendRedirect("result.jsp");~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
在result.jsp中将存在session中的list取出来,并将里面的bookbean对象的所有信息逐个输出首项获得list: Vector list=(Vector)session.getAttribute("list"); bookbean book=new bookbean();然后输出:
for(int i=0;i<list.size();i++){
book=(bookbean)list.get(i);
out.print("<tr>");
out.print("<td>");out.print(book.getName());out.print("</td>");
out.print("<td>");out.print(book.getId());out.print("</td>");
out.print("<td>");out.print(book.getAuthor());out.print("</td>");
out.print("<td>");out.print(book.getPrice());out.print("</td>");
out.print("<td>");out.print(book.getType());out.print("</td>");
out.print("</tr>");
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
基本上就是上面的过程,运行没有错误,tomcat也没有出现错误,可就是不显示查询的结果
只有
我测试了一下,去掉关于Vector 的所有内容,session中只存一个bookbean对象,result也只该bookbean的所有信息
,结果正确~~~~~~~~~~~~~~~~~,我很费解,研究了好长时间,仍然不行,还请高手指点一下。
那你把Vector list=(Vector)session.getAttribute("list");
改成List试试