求一段图书查找代码,用JSP写的,具体功能要求是输入书名点击查询可以调转到所查询图书的页面

有得请发binshuang1@163.com....谢谢啦... 有得请发binshuang1@163.com....谢谢啦 展开
 我来答
心有灵犀凝眸
2011-12-31
知道答主
回答量:8
采纳率:0%
帮助的人:6.8万
展开全部
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
head>
<body bgcolor="cyan">
<center>
<h1 align="center" class="STYLE1">请输入要查询的关键字</h1>
<form action="jie.jsp" method="post">
<span class="STYLE2">请选择查询条件</span>
<select name="condition">
<option values ="author">作者</option>
<option values ="name" selected="selected">书名</option>
</select>
<span class="STYLE3">请输入</span>
<input type="text" name="name" /><br />
<input type="submit" value="提交" />
</form>
</body>
</html>
跳转后的页面:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<head>
<%@ page import="test.BookCo" %>
<%@ page import="java.sql.*" %>
<body>
<jsp:useBean id="Co" class="test.BookCo" scope="application">
</jsp:useBean>
<center>
<h1>图书信息</h1>
<table border="1" width="80%">
<th>书号</th><th>书名</th><th>作者</th><th>出版社</th><th>书籍简介</th>
<%
String name=request.getParameter("name");
String condition=request.getParameter("condition");
Co.setKeyword(name,condition);
ResultSet rs=Co.Boo();
while(rs.next())
{
out.print("<tr><td>"+rs.getInt("bId")+"</td>");
out.print("<td>"+rs.getString("bName")+"</td>");
out.print("<td>"+rs.getString("bAuthor")+"</td>");
out.print("<td>"+rs.getString("bPress")+"</td>");
out.print("<td>"+rs.getString("bInfo")+"</td></tr>");
}
rs.close();
%>
</table>
</center>
</body>
</html>

javabean部分:
package test;
import java.sql.*;
import java.io.*;
import java.util.*;
public class BookCo{
public String name,condition;
Connection con=null;
String strurl="jdbc:odbc:bookstore";
Statement stmt=null;
ResultSet rs=null;
public BookCo()
{
name="";
condition="";
}
public void setKeyword(String s,String ss)
{
name=s;
condition=ss;
try{
byte[] b=name.getBytes("iso-8859-1");
name=new String(b);
byte[] bb=condition.getBytes("iso-8859-1");
condition=new String(bb);
}
catch(Exception e){System.out.println("error1:"+e.getMessage());}
}
public ResultSet Boo()
{
String drivername="sun.jdbc.odbc.JdbcOdbcDriver";
String sql="select * from books";
try {
Class.forName(drivername);
con=DriverManager.getConnection(strurl);
stmt=con.createStatement();
if(condition.equals("作者")){
sql="select * from books where bAuthor='"+name+"'";
}
else
if(condition.equals("书名"))
{
sql="select * from books where bName='"+name+"'";
}
rs=stmt.executeQuery(sql);
}
catch (Exception e){
System.out.println("connection fail!");
}
return rs;
}}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式