package com.tutorialspoint.admin;
import java.sql.*;
import java.util.Collection;
import java.util.Map;
import java.util.Vector;
import bean.*;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.io.*;
public class BooklistAction extends ActionSupport{
private String op = "";
private String currentpage = "";
private String bookid="";
private String bookname="";
private String author="";
private String publisherid="";
private String pubdate="";
private String price="";
private String quantity="";
private String place="";
private String type="";
private String content="";
private String error="";
private String pubdate2="";
private String price2="";
private String quantity2="";
private String where="";
private String picture="";
private String employeeid="";
private String password="";
private int i_totalnum=0; //总记录数
private int i_pagenum=10; //一页显示的记录数码
private int i_totalpage=0; //总页数
private int i_currentpage=1; //当前页
private String totalnum=null; //总记录数
private String totalpage=null; //总页数
private File s_picture = null;//上传的文件
private String imageFileName; //文件名称
private String imageContentType; //文件类型
private bookBean book = null;
private publisherBean publisher=null;
public String execute() throws Exception{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:bookshoplk","sa","");
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet rs=null;
if(op.equals("index")){
return index(stmt,rs);
}
if(op.equals("add")){
publisher(stmt,rs);
return "add";
}
if(op.equals("addgo")){
return addgo(stmt,rs);
}
if(op.equals("search"))
{
publisher(stmt,rs);
return "search";
}
if(op.equals("searchgo")){
searchgo();
show(stmt,rs);
return "searchgo";
}
if(op.equals("delete")){
stmt.executeUpdate("delete from book where bookid='"+bookid+"'");
show(stmt,rs);
return "success";
}
if(op.equals("editshow")){
editshow(stmt,rs);
return "editshow";
}
if(op.equals("edit")){
return edit(stmt,rs);
}
if(op.equals("upload"))
{
String realpath = "D:\\myeclipse1\\MyBookStore\\WebRoot\\images";
try {
FileOutputStream fos = new FileOutputStream(realpath+"\\"+imageFileName);
FileInputStream fis = new FileInputStream(s_picture);
byte[] buffer = new byte[1024];
int len = 0;
try {
while((len = fis.read(buffer)) > 0){
fos.write(buffer, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
stmt.executeUpdate("update book set picture='"+imageFileName+"' where bookid='"+bookid+"'");
editshow(stmt,rs);
show(stmt,rs);
return "success";
}
else{
show(stmt,rs);
return "success";
}
}
public String index(Statement stmt,ResultSet rs)throws Exception{
rs=stmt.executeQuery("select * from employee where employeeid='"+employeeid+"' and password='"+password+"'");
if(rs.next()){
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put("admin",employeeid);
show(stmt,rs);
return "success";
}
else{
error+="用户名或密码不正确";
return "error";
}
}
public void publisher(Statement stmt,ResultSet rs)throws Exception{
Collection b_publisher=new Vector();
rs=stmt.executeQuery("select * from publisher ");
while(rs.next()){
publisher = new publisherBean();
publisher.publisherid = rs.getString("publisherid");
publisher.name = rs.getString("name");
b_publisher.add(publisher);
}
ActionContext.getContext().getSession().put("b_publisher",b_publisher);
}
public void show(Statement stmt,ResultSet rs) throws Exception{
if(op==null)
{
where="";
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
session.put("where",where);
}
rs=stmt.executeQuery("select count(*) from book where bookid is not null "+where);
rs.next();
i_totalnum=rs.getInt(1);
i_totalpage=i_totalnum/i_pagenum;
if(i_totalnum%i_pagenum!=0)
i_totalpage++;
if(op!=null&&op.equals("show"))
{
i_currentpage=Integer.parseInt(currentpage);
}
if(op!=null&&op.equals("previous"))
{
i_currentpage=Integer.parseInt(currentpage)-1;
}
if(op!=null&&op.equals("next"))
{
i_currentpage=Integer.parseInt(currentpage)+1;
}
if(op!=null&&op.equals("firstpage"))
{
i_currentpage=1;
}
if(op!=null&&op.equals("lastpage"))
{
i_currentpage=i_totalpage;
}
rs=stmt.executeQuery("select * from book left join publisher on book.publisherid=publisher.publisherid where bookid is not null "+where+" order by bookid ");
if(i_currentpage>i_totalpage)
i_currentpage=i_totalpage;
int i_position=(i_currentpage-1)*i_pagenum;
if(i_position==0)
rs.beforeFirst();
else
rs.absolute(i_position);
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();
Collection b_book=new Vector();
for(int i=0;i<i_pagenum;i++)
{
bookBean bookbean=new bookBean();
if(!rs.isLast()){
rs.next();
bookbean.bookid=(rs.getString("bookid")!=null?rs.getString("bookid"):"");
bookbean.bookname=(rs.getString("bookname")!=null?rs.getString("bookname"):"");
bookbean.author=(rs.getString("author")!=null?rs.getString("author"):"");
bookbean.price=(rs.getString("price")!=null?rs.getString("price"):"");
bookbean.type=(rs.getString("type")!=null?rs.getString("type"):"");
bookbean.quantity=(rs.getString("quantity")!=null?rs.getString("quantity"):"");
bookbean.place=(rs.getString("place")!=null?rs.getString("place"):"");
bookbean.publisherid=(rs.getString("name")!=null?rs.getString("name"):"");
if(bookbean.type.equals("0"))
bookbean.type="普通";
if(bookbean.type.equals("1"))
bookbean.type="新书";
if(bookbean.type.equals("2"))
bookbean.type="精品";
b_book.add(bookbean);
}
else
break;
}
session.put("book",b_book);
totalnum= i_totalnum+""; //总记录数
totalpage=i_totalpage+""; //总页数
currentpage=i_currentpage+""; //当前页
}
public String addgo(Statement stmt,ResultSet rs)throws Exception{
content=content.replaceAll("\n","<br>");
content=content.replaceAll(" "," ");
String s_sql="insert into book(bookid,bookname,author,publisherid,pubdate,price,quantity,place,type,content) "+
"values('"+bookid+"','"+bookname+"','"+author+"','"+publisherid+"','"+pubdate+"','"+price+"','"+quantity+"','"+place+"','"+type+"','"+content+"')";
try{
stmt.executeUpdate(s_sql);
}catch(Exception e){
error+="新建图书出错:"+e.getMessage();
return error;
}
show(stmt,rs);
return "addgo";
}
public void searchgo(){
if(!bookid.equals(""))
where+=" and bookid like'%"+bookid+"%' ";
if(!bookname.equals(""))
where+=" and bookname like'%"+bookname+"%' ";
if(!author.equals(""))
where+=" and author like'%"+author+"%' ";
if(!publisherid.equals(""))
where+=" and book.publisherid ='"+publisherid+"' ";
if(!pubdate.equals(""))
where+=" and pubdate >='"+pubdate+"' ";
if(!pubdate2.equals(""))
where+=" and pubdate <='"+pubdate2+"' ";
if(!price
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于Java web的书店系统 (206个子文件)
BooklistAction.class 16KB
OrderlistAction.class 11KB
UserinfolistAction.class 10KB
NoteslistAction.class 10KB
PublisherlistAction.class 10KB
EmployeelistAction.class 10KB
BookSearchAction.class 9KB
OrderSecond.class 8KB
MyOrderAction.class 8KB
LeaveWordShowAction.class 7KB
CartAction.class 5KB
ChangeUserinfoAction.class 5KB
TopAction.class 5KB
OrderFirstAction.class 4KB
RegisterAction.class 4KB
Login.class 3KB
IndexAction.class 3KB
ChangePasswordAction.class 2KB
LeaveWordAction.class 2KB
IncreaseCartAction.class 2KB
DecreaseCart.class 2KB
DeleteCartAction.class 2KB
BookDetailAction.class 2KB
ClearCartAction.class 1KB
ExitAction.class 807B
orderBean.class 753B
bookBean.class 582B
cartBean.class 527B
userinfoBean.class 449B
orderdetailBean.class 435B
employeeBean.class 429B
publisherBean.class 418B
noteBean.class 416B
.classpath 529B
org.eclipse.wst.common.component 471B
org.eclipse.wst.jsdt.ui.superType.container 49B
maincss.css 507B
Thumbs.db 99KB
研究日志(5人).doc 1.1MB
会议备忘录.doc 46KB
视频说明.docx 11KB
adin_r1.gif 40KB
0201008.gif 10KB
0204012.gif 9KB
angle.gif 7KB
adin_r5.gif 3KB
adin_r2.gif 2KB
adin_r4.gif 2KB
adin_r6.gif 2KB
adin_r3.gif 1KB
freemarker-2.3.19.jar 909KB
struts2-core-2.3.16.3.jar 782KB
xwork-core-2.3.16.3.jar 639KB
javassist-3.11.0.GA.jar 600KB
commons-collections-3.1.jar 546KB
commons-lang3-3.1.jar 308KB
ognl-3.0.6.jar 223KB
commons-io-2.2.jar 170KB
commons-fileupload-1.3.1.jar 67KB
BooklistAction.java 15KB
OrderlistAction.java 10KB
PublisherlistAction.java 10KB
UserinfolistAction.java 9KB
EmployeelistAction.java 9KB
NoteslistAction.java 9KB
BookSearchAction.java 9KB
MyOrderAction.java 6KB
OrderSecond.java 6KB
LeaveWordShowAction.java 6KB
CartAction.java 4KB
ChangeUserinfoAction.java 4KB
TopAction.java 4KB
OrderFirstAction.java 3KB
RegisterAction.java 3KB
Login.java 2KB
IndexAction.java 2KB
LeaveWordAction.java 2KB
DecreaseCart.java 1KB
IncreaseCartAction.java 1KB
ChangePasswordAction.java 1KB
DeleteCartAction.java 1KB
BookDetailAction.java 1KB
ClearCartAction.java 950B
orderBean.java 386B
ExitAction.java 360B
bookBean.java 348B
userinfoBean.java 271B
noteBean.java 251B
employeeBean.java 242B
publisherBean.java 222B
orderdetailBean.java 221B
cartBean.java 220B
9330998.jpg 95KB
20302264.jpg 86KB
goinadmin.jpg 30KB
031203.jpg 23KB
goin.jpg 22KB
031207.jpg 21KB
040601.jpg 20KB
20137213.jpg 18KB
共 206 条
- 1
- 2
- 3
资源评论
skyleebc
- 粉丝: 4
- 资源: 14
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于python实现的基于PyQt5和爬虫的小说阅读系统.zip
- 机械设计整经机上纱自动化sw20非常好的设计图纸100%好用.zip
- Screenshot_20240427_031602.jpg
- 网页PDF_2024年04月26日 23-46-14_QQ浏览器网页保存_QQ浏览器转格式(6).docx
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功