returnsubaction.java

来自「一个基本的图书馆管理系统」· Java 代码 · 共 69 行

JAVA
69
字号
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.NotFindActionException;
import c18.util.ConvertUtil;

/** 
 * 
 * 归还Action类
 * @struts.action path="/returnsub" scope="request"
 * @struts.action-forward name="success" path="/optresult.jsp"
 */
public class ReturnSubAction extends Action {
	private static final Log log = LogFactory.getLog(ReturnSubAction.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.isManager(request, response)){
			return mapping.findForward("/main");
		}
		
		//得到借阅号
		int borrowNo =0;
		String sborrowNo = request.getParameter("borrowNo");
		if(sborrowNo != null && !sborrowNo.equals("")){
			borrowNo = ConvertUtil.convertInt(sborrowNo);
		}
		try {
			//创建BorrowService对象
			BorrowService borrowservice = new BorrowServiceImpl(); 
			//归还
			borrowservice.returnSub(borrowNo);
			
		} catch (ActionException e) {
			//没有对应信息
			if(e instanceof NotFindActionException){
				request.setAttribute("errorString", e.getExceptionString());
				return mapping.findForward("success");
			}
			
			log.error(e);
		}
		
		return mapping.findForward("success");
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?