preborrowaction.java
来自「一个基本的图书馆管理系统」· Java 代码 · 共 75 行
JAVA
75 行
package c18.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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 c18.service.BorrowService;
import c18.service.BorrowServiceImpl;
import c18.session.UserSession;
import c18.struts.action.exception.ActionException;
import c18.struts.action.exception.ExistReferActionException;
import c18.struts.action.exception.NotEnoughActionException;
import c18.util.ConvertUtil;
/**
*
* 预借图书Action类
* @struts.action path="/preborrow"scope="request"
* @struts.action-forward name="success" path="/optresult.jsp"
*/
public class PreBorrowAction extends Action {
private static final Log log = LogFactory.getLog(PreBorrowAction.class);
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
//判断是否登陆
if(!UserSession.isLogin(request, response)){
return mapping.findForward("/main");
}
//得到图书号
int bookNo =0;
String sbookNo = request.getParameter("bookNo");
if(sbookNo != null && !sbookNo.equals("")){
bookNo = ConvertUtil.convertInt(sbookNo);
}
try {
//预借图书
BorrowService borrowservice = new BorrowServiceImpl();
borrowservice.preBorrow(UserSession.getSession(request, response).getUserNo(), bookNo);
} catch (ActionException e) {
//余量不足
if(e instanceof NotEnoughActionException){
request.setAttribute("errorString", e.getExceptionString());
return mapping.findForward("success");
}else
//已有未处理预借或已借阅
if(e instanceof ExistReferActionException){
request.setAttribute("errorString", e.getExceptionString());
return mapping.findForward("success");
}
log.error(e);
}
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?