package action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.bookdao;
import actionform.bookform;
public class add extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm actionform,HttpServletRequest request,HttpServletResponse response)
{
bookform book=(bookform)actionform;
String sql="insert into book(author,title,publish,time,price) values ('"+book.getAuthor()+"','"+book.getTitle()+"','"+book.getPublish()+"','"+book.getTime()+"','"+book.getPrice()+"')";
bookdao dao=new bookdao();
int i= dao.getadd(sql);
System.out.println(sql);
request.setAttribute("book", book);
if(i>0){
return mapping.findForward("select");
}else{
return mapping.findForward("select");
}
}
}
package action;
import javax.servlet.http.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionMapping;
import com.bookdao;
import actionform.bookform;
public class del extends Action{
public ActionForward execute (ActionMapping mapping,ActionForm actionform,HttpServletRequest request,HttpServletResponse response)
{
System.out.print("阿里巴巴");
// bookform book =(bookform)actionform;
String id=request.getParameter("id");
bookdao bookdao =new bookdao();
String sql="delete from book where id='"+id+"'";
int i=bookdao.getadd(sql);
if(i>0){
System.out.println("删除成功");
request.setAttribute("message", "添加成功");
return mapping.findForward("list1");
}else{return mapping.findForward("failure");}
}
}
///
package action;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.DBConnection;
import com.bookdao;
import actionform.bookform;
public class recycle extends Action{
public ActionForward execute (ActionMapping mapping,ActionForm actionform,HttpServletRequest request,HttpServletResponse response)
{
// bookform book = (bookform)actionform;
int begin_no=0; //开始的rownum记录号
int end_no=0; //结束的rownum记录号
ResultSet rs = null;
// 获得当前页码
int pageNo = 1;
try {
pageNo = Integer.parseInt(request.getParameter("pageNo"));
} catch(Exception ex) {
}
if (pageNo < 1) {
pageNo = 1;
}
request.setAttribute("pageNo", pageNo);
List list = new ArrayList();
int count = 0;
// 根据页码从数据库中获得对应的数据
try {
DBConnection db= new DBConnection();
Connection con;
Statement stm;
con=db.getConnection();
stm=con.createStatement();
begin_no=1+(5*(pageNo-1));
end_no = 5+(5*(pageNo-1));
rs=stm.executeQuery("select * from (select rownum row_id ,id,author,title,publish,time,price,del from (select id,author,title,publish,time,price,del from book where del=0)) where row_id between " +begin_no+ " and " +end_no );
// rs=stm.executeQuery("select * from (select rownum row_id ,id,author,title,publish,time,price,del from (select id,author,title,publish,time,price,del from book order by id desc)) where row_id between " +begin_no+ " and " +end_no );
while (rs.next()) {
bookform bean = new bookform();
bean.setId(rs.getString("id"));
bean.setAuthor(rs.getString("author"));
bean.setTitle(rs.getString("title"));
bean.setPublish(rs.getString("publish"));
bean.setTime(rs.getString("time"));
bean.setPrice(rs.getString("price"));
bean.setDel(rs.getString("del"));
list.add(bean);
}
rs.close();
// rs = stm.executeQuery("select * from book where del=1 ");
rs = stm.executeQuery("select count(*) from book where del=0 ");
if (rs.next()) {
count = rs.getInt(1);
}
} catch(Exception ex) {
ex.printStackTrace();
}
request.setAttribute("count", count);
request.setAttribute("list", list);
// String sql="select*from book";
// bookdao bookdao= new bookdao();
// ArrayList list=bookdao.getSelect(sql);
// request.setAttribute("list", list);
return mapping.findForward("list5");
}
}
//
package action;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.DBConnection;
import com.bookdao;
import actionform.bookform;
public class select extends Action{
public ActionForward execute (ActionMapping mapping,ActionForm actionform,HttpServletRequest request,HttpServletResponse response)
{
// bookform book = (bookform)actionform;
int begin_no=0; //开始的rownum记录号
int end_no=0; //结束的rownum记录号
ResultSet rs = null;
// 获得当前页码
int pageNo = 1;
try {
pageNo = Integer.parseInt(request.getParameter("pageNo"));
} catch(Exception ex) {
}
if (pageNo < 1) {
pageNo = 1;
}
request.setAttribute("pageNo", pageNo);
List list = new ArrayList();
int count = 0;
// 根据页码从数据库中获得对应的数据
try {
DBConnection db= new DBConnection();
Connection con;
Statement stm;
con=db.getConnection();
stm=con.createStatement();
begin_no=1+(5*(pageNo-1));
end_no = 5+(5*(pageNo-1));
rs=stm.executeQuery("select * from (select rownum row_id ,id,author,title,publish,time,price,del from (select id,author,title,publish,time,price,del from book where del=1)) where row_id between " +begin_no+ " and " +end_no );
// rs=stm.executeQuery("select * from (select rownum row_id ,id,author,title,publish,time,price,del from (select id,author,title,publish,time,price,del from book order by id desc)) where row_id between " +begin_no+ " and " +end_no );
while (rs.next()) {
bookform bean = new bookform();
bean.setId(rs.getString("id"));
bean.setAuthor(rs.getString("author"));
bean.setTitle(rs.getString("title"));
bean.setPublish(rs.getString("publish"));
bean.setTime(rs.getString("time"));
bean.setPrice(rs.getString("price"));
bean.setDel(rs.getString("del"));
list.add(bean);
}
rs.close();
// rs = stm.executeQuery("select * from book where del=1 ");
rs = stm.executeQuery("select count(*) from book where del=1 ");
if (rs.next()) {
count = rs.getInt(1);
}
} catch(Exception ex) {
ex.printStackTrace();
}
request.setAttribute("count", count);
request.setAttribute("list", list);
// String sql="select*from book";
// bookdao bookdao= new bookdao();
// ArrayList list=bookdao.getSelect(sql);
// request.setAttribute("list", list);
return mapping.findForward("list");
}
}
package action;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.bookdao;
import actionform.bookform;
public class select1 extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm actionform,HttpServletRequest request,HttpServletResponse response)
{
bookform book =(bookform)actionform;
bookdao bookdao= new bookdao();
String id=request.getParameter("id");
String sql="update book set del=0 where id='"+id+"'";
int i=bookdao.getadd(sql);
if(i>0){
System.out.println("添加成功");
request.setAttribute("message", "添加成功");
return mapping.findForward("list3");
}else{
request.setAttribute("message", "添加失败");
return mapping.findForward("failure");
}
}
}
//
package action;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import com.bookdao;
import actionform.bookform;
public class up extends Action {
public ActionForward execute(ActionMapping mapping,ActionForm actionform,HttpServletRequest request,HttpServletResponse response)
{
bookform book =(bookform)actionform;
bookdao bookdao= new bookdao();
String id=request.getParameter("id");
String author=request.getParameter("author");
String title=request.getParameter("title");
String publish=request.getParameter("publish");
String time =request.getParameter("time");
String price=request.getParameter("price");
String sql="update book set author='"+author+"',title='"+title+"',publish='"+publish+"',time='"+time+"',price='"+price+"' where id='"+id+"'";
int i=bookdao.getadd(sql);
if(i>0){
System.out.println("添加成功");
request.setAttribute("message", "添加成功");
return mapping.findForward("list2");
}else{
request.setAttribute("message", "添加失败");
return mapping.findForward("failure");
}
}
}
package action;
import java.util.ArrayList;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bookdao;
import actionform.bookform;
public class up1 extends Action{
public ActionForward execute (ActionMapping mapping,ActionForm actionform,HttpServletRequest request,HttpServletResponse response)
{
String id=request.getParameter("id");
bookform book = (bookform)actionform;
String sql="select*from book where id='"+id+"'";
bookdao bookdao= new bookdao();
ArrayList list=bookdao.getSelect(sql);
request.setAttribute("list", list);
return mapping.findForward("update");
}
}