📄 bookmanageraction.java
字号:
/*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package com.autumn.struts.action;
import java.io.UnsupportedEncodingException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.actions.DispatchAction;
import com.autumn.pojo.Book;
import com.autumn.pojo.Reader;
import com.autumn.pojo.oper.Factory;
/**
* MyEclipse Struts
* Creation date: 06-19-2008
*
* XDoclet definition:
* @struts.action path="/bookmanager" name="bookForm" input="/bookoper.jsp" parameter="status" scope="request" validate="true"
* @struts.action-forward name="bookoper" path="/bookoper.jsp"
*/
public class BookmanagerAction extends DispatchAction {
/*
* Generated Methods
*/
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward check(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;// TODO Auto-generated method stub
String rid = bookForm.getString("rid") ;
String bcode = bookForm.getString("bcode") ;
ActionMessages errors = new ActionMessages() ;
if(rid==null||"".equals(rid)||bcode==null||"".equals(bcode))
{
errors.add("bookout", new ActionMessage("outmes.null")) ;
super.saveErrors(request, errors) ;
return mapping.getInputForward() ;
}
Reader reader = Factory.getReaderOperIntance().queryById(rid) ;
Book book = Factory.getBookOperInstance().queryByCode(bcode) ;
if(reader==null)
{
errors.add("outmes", new ActionMessage("reader.err")) ;
super.saveErrors(request, errors) ;
return mapping.getInputForward();
}
if(book==null)
{
errors.add("outmes", new ActionMessage("book.err")) ;
super.saveErrors(request, errors) ;
return mapping.getInputForward() ;
}
if(book.getOut()==1)
{
errors.add("outmes", new ActionMessage("book.out")) ;
super.saveErrors(request, errors) ;
return mapping.getInputForward() ;
}
request.setAttribute("reader", reader) ;
request.setAttribute("book",book) ;
return mapping.findForward("outmessage");
}
public ActionForward back(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;
String bcode = bookForm.getString("bcode") ;
boolean suc = Factory.getBorrowedOperInstance().delete(bcode) ;
String success = null ;
if(suc)
{
success = "suc" ;
}
request.setAttribute("success", success) ;
return mapping.findForward("outmessage") ;
}
public ActionForward out(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;
String bcode = bookForm.getString("bcode") ;
String rid = bookForm.getString("rid") ;
boolean suc = Factory.getBorrowedOperInstance().add(bcode, rid) ;
String success = null ;
if(suc)
{
success = "suc" ;
}
request.setAttribute("success", success) ;
return mapping.findForward("outmessage");
}
public ActionForward queryreader(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;
String cond = bookForm.getString("cond") ;
List all =null;
all= Factory.getReaderOperIntance().queryByLike(cond) ;
String query = "query" ;
request.setAttribute("readers", all) ;
request.setAttribute("query", query) ;
return mapping.findForward("readerinfo");
}
public ActionForward querybook(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;
String cond = bookForm.getString("cond") ;
List all =null;
all = Factory.getBookOperInstance().queryByLike(cond) ;
request.setAttribute("books", all) ;
return mapping.findForward("bookinfo");
}
//添加图书
public ActionForward addbook(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;
String bid=bookForm.getString("bid") ;
String bcode=bookForm.getString("bcode") ;
String bname=bookForm.getString("bname") ;
String publisher=bookForm.getString("publisher") ;
String author=bookForm.getString("author") ;
String price = bookForm.getString("price");
int pagecount = (Integer)bookForm.get("pagecount") ;
ActionMessages errors = new ActionMessages() ;
if(bid==null||"".equals(bid)||bcode==null||"".equals(bcode)||bname==null||"".equals(bname)||publisher==null||"".equals(publisher)||author==null||"".equals(author)||price==null||"".equals(price))
{
request.setAttribute("bookinfo","err") ;
return mapping.findForward("addbook") ;
}
if(Factory.getBookOperInstance().queryByCode(bcode)!=null)
{
request.setAttribute("bookdu", "yes") ;
}
Book book = new Book() ;
book.setId(bid) ;
book.setCode(bcode) ;
try {
book.setName(new String(bname.getBytes("gbk"),"iso8859-1")) ;
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
book.setPublish(new String(publisher.getBytes("gbk"),"iso8859-1")) ;
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
book.setAuthor(new String(author.getBytes("gbk"),"ISO8859-1")) ;
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
book.setPrice(price) ;
book.setPagecount(pagecount) ;
boolean suc =false ;
request.setAttribute("add", "yes") ;//判断是否添加,若没有经过添加,则在页面不显示结果信息
try {
suc = Factory.getBookOperInstance().insert(book) ;
} catch (RuntimeException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(suc)
{
request.setAttribute("suc", "s") ;
}
return mapping.findForward("addbook") ;
}
//查询准备删除的图书的信息
public ActionForward deletequery(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;
String bcode = bookForm.getString("bcode") ;
if(bcode==null||"".equals(bcode))
{
request.setAttribute("bcodenull", "yes") ;
return mapping.findForward("deletebook") ;
}
Book book = Factory.getBookOperInstance().queryByCode(bcode) ;
request.setAttribute("query", "yes") ;
request.setAttribute("book", book) ;
return mapping.findForward("deletebook");
}
//删除图书
public ActionForward delete(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm bookForm = (DynaActionForm) form;
String bcode = bookForm.getString("bcode") ;
Book b = Factory.getBookOperInstance().queryByCode(bcode) ;
boolean suc = Factory.getBookOperInstance().delete(b) ;
if(suc)
{
request.setAttribute("suc", "s") ;
}else{
request.setAttribute("suc", "f") ;
}
return mapping.findForward("deletebook");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -