求J2EE的网上图书销售系统
发布网友
发布时间:2022-05-16 10:39
我来回答
共4个回答
热心网友
时间:2023-10-19 22:33
1)getRequest()方法
该方法负责从页面接收到的表单资料分解,并设置图书实体的相应属性,它的返回值为Boolean类型,true表示成功,反之表示失败。部分代码如下:
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(to_String(bookname));
String author = request.getParameter("author");
if (author==null || author.equals(""))
{
author = "";
sqlflag = false;
}
abooks.setAuthor(to_String(author));
String publish = request.getParameter("publish");;
if (publish==null)
{
publish = "";
}
abooks.setPublish(to_String(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(to_String(bookno));
String picture = request.getParameter("picture");
if (picture == null)
{
picture = "images/01.gif";
}
abooks.setPicture(to_String(picture));
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(to_String(content));
if (sqlflag)
{
flag = true;
}
return flag;
}catch (Exception e){
return flag;
}
}
2)book_search()方法
该方法负责图书查询,包括图书的分类,分页、关键字查询。首先通过getRequest()方法获得页面表单参数值,根据参数值判断是何种查询,然后根据相应的SQL的语句从数据库里查询相应的值。这里需要用到分页技术。
部分代码如下:
/**
* 完成图书查询,包括分类,分页查询
* @param res
* @return
* @throws java.lang.Exception
*/
public boolean book_search(HttpServletRequest res) throws Exception {
DataBase db = new DataBase();
db.connect();
Statement stmt = db.conn.createStatement ();
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 = to_String(keyword).toUpperCase();
try {
page = Integer.parseInt(PAGE);
}catch (NumberFormatException e){
page = 1;
}
//取出记录数
if (!classid.equals("") && keyword.equals("") ) {
sqlStr = "select count(*) from book where bookclass='"+classid + "'";
}
else if (!keyword.equals("")) {
if (classid.equals("")){
sqlStr = "select count(*) from book where upper(bookname) like '%" +
keyword+ "%' or upper(content) like '%" + keyword + "%'";
} else {
sqlStr = "select count(*) from book where bookclass='" + classid
+ "' and (upper(bookname) like '%" +keyword+ "%' or "+
"upper(content) like '%" + keyword + "%')";
}
} else {
sqlStr = "select count(*) from book";
}
int rscount = pageSize;
try {
ResultSet rs1 = stmt.executeQuery(sqlStr);
if (rs1.next()) recordCount = rs1.getInt(1);
rs1.close();
}catch (SQLException e){
System.out.println(e.getMessage());
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 a.id,a.bookname,a.bookclass,b.classname,"+
"a.author,a.publish,a.bookno,a.content,a.prince,a.amount,"+
"a.Leav_number,a.regtime,a.picture from book a,bookclass b"+
" where a.Bookclass = b.Id ";
if (!classid.equals("") && keyword.equals("") ){ //如果类别不为空,非查询
if (page == 1)
{
sqlStr = sqlStr + " and a.bookclass='" + classid + "' "+
"order by a.Id desc";
} else {
sqlStr = sqlStr + " and a.bookclass='" + classid + "limit "+
(recordCount-pageSize * page)+","+(recordCount-pageSize * (page-1));
}
} else if (!keyword.equals("")) { //如果是查询资料
if (page == 1){
if (!classid.equals("")) {//查询某一类
sqlStr = sqlStr + "and a.Bookclass='" +
classid + "' and (upper(a.bookname) like '%" +
keyword+ "%' or upper(a.content) like '%" +
keyword + "%') order by a.Id desc";
} else { //查询所有类
sqlStr = sqlStr + " and (upper(a.bookname) like '%" +
keyword+ "%' or upper(a.content) like '%" +
keyword + "%') order by a.Id desc";
}
} else {
if (!classid.equals("")){
sqlStr = sqlStr + " and a.Bookclass='" +
classid + "' and (upper(a.bookname) like '%" +
keyword+ "%' or upper(a.content) like '%" +
keyword + "%') limit "+(recordCount-pageSize * page)+","+
(recordCount-pageSize * (page-1));
} else {
sqlStr = sqlStr + " and (upper(a.bookname) like '%" +
keyword+ "%' or upper(a.content) like '%" +
keyword + "%') limit "+(recordCount-pageSize * page)+","+
(recordCount-pageSize * (page-1));
}
}
} else {//非查询,也非分类浏览
if (page == 1){
sqlStr = sqlStr + " order by a.Id desc limit 0,"+pageSize;
} else {
sqlStr = sqlStr + "limit "+(recordCount-pageSize * page)+","+
(recordCount-pageSize * (page-1));
}
}
try {
rs = stmt.executeQuery(sqlStr);
booklist = new Vector(rscount);
while (rs.next()){
book book = new book();
book.setId(rs.getLong("id"));
book.setBookName(rs.getString("bookname"));
book.setBookClass(rs.getInt("bookclass"));
book.setClassname(rs.getString("classname"));
book.setAuthor(rs.getString("author"));
book.setPublish(rs.getString("publish"));
book.setBookNo(rs.getString("Bookno"));
book.setContent(rs.getString("content"));
book.setPrince(rs.getFloat("prince"));
book.setAmount(rs.getInt("amount"));
book.setLeav_number(rs.getInt("leav_number"));
book.setRegTime(rs.getString("regtime"));
book.setPicture(rs.getString("picture"));
booklist.addElement(book);
}
rs.close();
return true;
}catch (Exception e){
System.out.println(e.getMessage());
return false;
}
}
3)insert()方法
该方法负责图书的添加,返回类型为Boolean型,true表示成功,反之失败。首先从图书对象中获得属性,组装相应的SQL语句并执行,返回执行结果。代码如下:
/**
* 完成图书添加
* @return
* @throws java.lang.Exception
*/
public boolean insert() throws Exception {
sqlStr = "insert into book (Bookname,Bookclass,Author,Publish,Bookno,"+
"Content,Prince,Amount,Leav_number,Regtime,picture) values ('";
sqlStr = sqlStr + dataFormat.toSql(abooks.getBookName()) + "','";
sqlStr = sqlStr + abooks.getBookClass() + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getAuthor()) + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getPublish()) + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getBookNo()) + "','";
sqlStr = sqlStr + dataFormat.toSql(abooks.getContent()) + "','";
sqlStr = sqlStr + abooks.getPrince() + "','";
sqlStr = sqlStr + abooks.getAmount() + "','";
sqlStr = sqlStr + abooks.getAmount() + "',";
sqlStr = sqlStr + "now()"+ ",'";
sqlStr = sqlStr + abooks.getPicture()+"')";
try{
System.out.print(sqlStr);
DataBase db = new DataBase();
db.connect();
stmt =db.conn.createStatement ();
stmt.execute(sqlStr);
return true;
}catch (SQLException sqle){
System.out.print(sqle.getMessage());
return false;
}
}
5.4客户界面设计
5.4.1界面头、界面尾设计
为了提高代码的重用性,我把客户界面部分相同的头和尾做成两个模块,分别命名为 head.inc 和tail.inc,这两个文件都是纯 HTML代码,在头和尾引入下面的两句代码方可;
<%@include file=”/bookshop/inc/head.inc”%>
<%@include file=”/bookshop/inc/tail.inc”%>
热心网友
时间:2023-10-19 22:34
OA、ERP、进销存、固定资产、工程项目、数字校园、物流,物业等多套管理系统,功能可定制,可OEM
热心网友
时间:2023-10-19 22:34
java与模式这本书不错。这本书讲java原理与模式设计,3框架的话没什么的。这些是小技巧。做一下项目就能懂,关键是java基础要打牢。
热心网友
时间:2023-10-19 22:35
直接一个标题叫什么系统,需求说明书呢?