⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 performbooknewsaudaction.java

📁 beginJsp2.0外文书籍源代码
💻 JAVA
字号:
package com.wrox.publish.action;import com.wrox.publish.bo.ActionDeniedException;import com.wrox.publish.bo.BookBO;import com.wrox.publish.om.BookNews;import java.util.HashMap;import java.util.Map;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.actions.LookupDispatchAction;/** * Struts Action invoked when the user wants to add, update or delete * a BookNews item in the database. The form button pressed determines  * the method the request is dispatched to. */public class PerformBookNewsAUDAction extends LookupDispatchAction {    /**      * Used by the superclass to determine which methods should be     * called in response to which buttons.     * @return A Map mapping button labels to the method name to invoke.     */        protected Map getKeyMethodMap() {        Map map = new HashMap();        map.put("booknews.add.button.label", "add");        map.put("booknews.update.button.label", "update");        map.put("booknews.delete.button.label", "delete");        return map;    }    /**      * Invoked by the Struts controller. This method is overridden to detect     * the use of the Cancel button; in that case the ActionForward labelled     * "cancel" is returned.     * @param mapping The ActionMapping invoking this Action.     * @param form The ActionForm. This <em>must</em> be a BookNews item.     * @param request The HTTP request.     * @param response The HTTP response.     * @return the ActionForward identifying where to go next.     * @throws Exception if an error occurred.     */        public ActionForward execute(ActionMapping mapping,                                  ActionForm form,                                 HttpServletRequest request,                                  HttpServletResponse response)     throws Exception {        if (request.getParameterMap().containsKey("id") ||            request.getParameterMap().containsKey("user") ||            request.getParameterMap().containsKey("published")) {            request.getSession().removeAttribute(mapping.getName());            throw new ActionDeniedException(                    "id, user and published are immutable");        }        if (isCancelled(request)) {            return mapping.findForward("cancel");        } else {            return super.execute(mapping, form, request, response);        }    }        /**      * Invoked by the superclass' dispatcher code when Add was pressed.     * @param mapping The ActionMapping invoking this Action.     * @param form The ActionForm. This <em>must</em> be a BookNews item.     * @param request The HTTP request.     * @param response The HTTP response.     * @return the ActionForward item labelled "added".     * @throws Exception if an error occurred.     */        public ActionForward add(ActionMapping mapping,                              ActionForm form,                             HttpServletRequest request,                              HttpServletResponse response)     throws Exception {        BookBO bookBO = BookBO.getInstance(request, getDataSource(request));        bookBO.create((BookNews)form);        return mapping.findForward("added");    }    /**      * Invoked by the superclass' dispatcher code when Update was pressed.     * @param mapping The ActionMapping invoking this Action.     * @param form The ActionForm. This <em>must</em> be a BookNews item.     * @param request The HTTP request.     * @param response The HTTP response.     * @return the ActionForward item labelled "updated".     * @throws Exception if an error occurred.     */        public ActionForward update(ActionMapping mapping,                                 ActionForm form,                                HttpServletRequest request,                                 HttpServletResponse response)     throws Exception {        BookBO bookBO = BookBO.getInstance(request, getDataSource(request));        bookBO.update((BookNews)form);        return mapping.findForward("updated");    }    /**      * Invoked by the superclass' dispatcher code when Delete was pressed.     * @param mapping The ActionMapping invoking this Action.     * @param form The ActionForm. This <em>must</em> be a BookNews item.     * @param request The HTTP request.     * @param response The HTTP response.     * @return the ActionForward item labelled "deleted".     * @throws Exception if an error occurred.     */        public ActionForward delete(ActionMapping mapping,                                 ActionForm form,                                HttpServletRequest request,                                 HttpServletResponse response)     throws Exception {        BookBO bookBO = BookBO.getInstance(request, getDataSource(request));        bookBO.remove((BookNews)form);        return mapping.findForward("deleted");    }}

⌨️ 快捷键说明

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