【Java开源代码栏目提醒】:网学会员Java开源代码为您提供booksmn.java参考,解决您在booksmn.java学习中工作中的难题,参考学习。
package org.pan.web;
import java.sql.*;
import java.util.Vector;
import org.pan.util.*;
import javax.servlet.http.HttpServletRequest;
import org.pan.
web.book.books;
/**
* Title: 图书类别列表
* Description:
* Copyright: Copyright (c) 2003
* Company: 多智能
网络有限公司
* @author: siny pan
* @version 1.0
*/
public class booksmn extends DataBase {
private books abooks = new books(); //新的图书类
private javax.servlet.http.HttpServletRequest request; //建立页面请求
private boolean sqlflag = true ; //对接收到的数据是否正确
private Vector booklist; //显示图书
列表向量数组
private int page = 1; //显示的页码
private int pageSize=10; //每页显示的图书数
private int pageCount =0; //页面总数
private long recordCount =0; //查询的记录总数
public booksmn() throws Exception{
super();
}
public Vector getBooklist() {
return booklist;
}
public boolean getSqlflag() {
return sqlflag;
}
public String getGbk( String str) {
try
{
return new String(str.getBytes("ISO8859-1"));
}
catch (Exception e)
{
return str;
}
}
//将页面表单传来的资料分解
public boolean getRequest(javax.servlet.http.HttpServletRequest newrequest) {
boolean flag = false;
try
{
request = newrequest;
String ID = request.getParameter("id");
long bookid = 0;
try
{
bookid = Long.parseLong(ID);
}
catch (Exception e)
{
}
abooks.setId(bookid);
String bookname = request.getParameter("bookname");
if (bookname==null || bookname.equals(""))
{
bookname = "";
sqlflag = false;
}
abooks.setBookName(getGbk(bookname));
String author = request.getParameter("author");
if (author==null || author.equals(""))
{
author = "";
sqlflag = false;
}
abooks.setAuthor(getGbk(author));
String publish = request.getParameter("publish");;
if (publish==null)
{
publish = "";
}
abooks.setPublish(getGbk(publish));
String bookclass = request.getParameter("bookclass");
int bc = Integer.parseInt(bookclass);
abooks.setBookClass(bc);
String bookno = request.getParameter("bookno");
if (bookno == null)
{
bookno = "";
}
abooks.setBookNo(getGbk(bookno));
float price;
try {
price =new Float(request.getParameter("price")).floatValue();
}
catch (Exception e)
{
price = 0;
sqlflag = false;
}
abooks.setPrince(price);
int amount;
try
{
amount = new Integer(request.getParameter("amount")).intValue();
}
catch (Exception e)
{
sqlflag = false;
amount = 0;
}
abooks.setAmount(amount);
String content = request.getParameter("content");
if (content == null)
{
content = "";
}
abooks.setContent(getGbk(content));
if (sqlflag)
{
flag = true;
}
return flag;
}
catch (Exception e)
{
return flag;
}
}
public String getSql() {
sqlStr = "select id,classname from my_Book order by id";
return sqlStr;
}
public boolean execute(HttpServletRequest res) throws Exception {
request = res;
String PAGE = request.getParameter("page"); //页码
String classid = request.getParameter("classid"); //分类ID号
String keyword = request.getParameter("keyword"); //查询关键词
if (classid==null) classid="";
if (keyword==null) keyword = "";
keyword = getGbk(keyword).toUpperCase();
try
{
page = Integer.parseInt(PAGE);
}
catch (NumberFormatException e)
{
page = 1;
}
//取出记录数
if (!classid.equals("") && keyword.equals("") ) {
sqlStr = "select count(*) from my_book where bookclass='" + classid + "'";
} else if (!keyword.equals("")) {
if (classid.equals(""))
{
sqlStr = "select count(*) from my_book where upper(bookname) like '%" +keyword+ "%' or upper(content) like '%" + keyword + "%'";
} else {
sqlStr = "select count(*) from my_book where bookclass='" + classid + "' and (upper(bookname) like '%" +keyword+ "%' or upper(content) like '%" + key
word + "%')";
}
} else {
sqlStr = "select count(*) from my_book";
}
int rscount = pageSize;
try
{
ResultSet rs1 = stmt.executeQuery(sqlStr);
if (rs1.next()) recordCount = rs1.getInt(1);
rs1.close();
}
catch (SQLException e)
{
return false;
}
//设定有多少pageCount
if (recordCount < 1)
pageCount = 0;
else
pageCount = (int)(recordCount - 1) / pageSize + 1;
//检查查看的页面数是否在范围内
if (page < 1)
page = 1;
else if (page > pageCount)
page = pageCount;
rscount = (int) recordCount % pageSize; // 最后一页记录数
//sql为倒序取值
sqlStr = "select to