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

📄 remulakservlet.java

📁 《Developing Applications with Java and UML》一书的源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        String custId = request.getParameter("customerId");        Integer customerId = new Integer(custId);        CustomerValue custVal = new CustomerValue();        custVal.setCustomerId(customerId);        custVal.setCustomerNumber(request.getParameter("customerNumber"));        AddressValue addrVal = new AddressValue();        RoleValue roleVal = new RoleValue();        // set an empty addrVal object into the Servlet Context        // so JSP's can see it        request.setAttribute("addrVal", addrVal);        request.setAttribute("custVal", custVal);        request.setAttribute("roleVal", roleVal);        // Forward to the JSP page used to actually display the page        forward("rltnAddress.jsp", request, response);    }    /**     * This operation represents the setup to add pathway through     * the Maintain Relationships Use Case     */     private void doRltnAddressDelete(HttpServletRequest request,        HttpServletResponse response)        throws IOException, ServletException {        logIt("RemulakServlet: doRltnAddressDelete");        Integer addressId = new Integer(request.getParameter("addressId"));        Integer roleId = new Integer(request.getParameter("roleId"));        UCMaintainRltnshp UCController = new UCMaintainRltnshp();        // call to controller method in session bean        UCController.rltnDeleteAddress(addressId, roleId);        //Requery        CustomerValue custVal = UCController.rltnCustomerInquiry(request.getParameter("customerNumber"));        // remove the UCMaintainRltnshp Controller        logIt("Removing the Controller");        UCController = null;        // set custVal object into the Servlet Context        // so JSP's can see it        request.setAttribute("custVal", custVal);        // Forward to the JSP page used to actually display the newly added        // Customer using a different JSP file        forward("rltnInquiry.jsp", request, response);    }    /**     * This operation represents the setup to add pathway through     * the Maintain Relationships Use Case     */     private void doRltnAddressEdit(HttpServletRequest request,        HttpServletResponse response)        throws IOException, ServletException {        logIt("RemulakServlet: doRltnAddressEdit");        UCMaintainRltnshp UCController = new UCMaintainRltnshp();        Integer addressId = new Integer(request.getParameter("addressId"));        logIt("RemulakServlet: after fetch for addressId");        // call to controller method in session bean        AddressValue addrVal = UCController.rltnAddressInquiry(addressId);        Integer roleId = new Integer(request.getParameter("roleId"));        // call to controller method in session bean        RoleValue roleVal = UCController.rltnRoleInquiry(roleId);        logIt("RemulakServlet: address line 1 " + addrVal.getAddressLine1());        logIt("RemulakServlet: customer line 1 " + roleVal.getRoleName());        CustomerValue custVal = new CustomerValue();        Integer customerId = new Integer(request.getParameter("customerId"));        custVal.setCustomerId(customerId);        custVal.setCustomerNumber(request.getParameter("customerNumber"));        // set the value objects into the Servlet Context so JSP's can see it        request.setAttribute("custVal", custVal);        request.setAttribute("addrVal", addrVal);        request.setAttribute("roleVal", roleVal);        // remove the UCMaintainRltnshp Controller        logIt("Removing the Controller");        UCController = null;        // Forward to the JSP page used to actually display the page        forward("rltnAddress.jsp", request, response);    }    /**     * This operation represents the setup to add address pathway through     * the Maintain Relationships Use Case     */     private void doRltnAddressAdd(HttpServletRequest request,        HttpServletResponse response)        throws IOException, ServletException {        logIt("RemulakServlet: doRltnAddressAdd");       UCMaintainRltnshp UCController = new UCMaintainRltnshp();        // Set the form values to an Address, Customer and Role Value objects        CustomerValue custVal = setAddrCustValueFromForm(request);        RoleValue roleVal = setAddrRoleValueFromForm(request);        AddressValue addrVal = setAddressValueFromForm(request);        logIt("RemulakServlet: after setaddressvalueform");        // call to controller method in session bean to add or update the Address        if (request.getParameter("addressId").length() == 0) {            logIt("RemulakServlet: Were adding");            UCController.rltnAddAddress(addrVal, custVal, roleVal); //Add            }        else {            logIt("RemulakServlet: Were updating");            logIt("addrid " + addrVal.getAddressId());            UCController.rltnUpdateAddress(addrVal, custVal, roleVal); //Update             }        //Requery        custVal = UCController.rltnCustomerInquiry(custVal.getCustomerNumber());        // remove the UCMaintainRltnshp Controller        logIt("Removing the Controller");        UCController = null;        // set custVal object into the Servlet Context        // so JSP's can see it        request.setAttribute("custVal", custVal);        // Forward to the JSP page used to actually display the newly added        // Customer using a different JSP file        forward("rltnInquiry.jsp", request, response);    }    /**     * Forwards the request to the specified relative URL.     */    private void forward(String url, HttpServletRequest request,        HttpServletResponse response)        throws IOException, ServletException {        RequestDispatcher rd = request.getRequestDispatcher(url);        rd.forward(request, response);    }    /**     * sets parms from form into CustomerValue object     */    private CustomerValue setCustomerValueFromForm(HttpServletRequest request)        throws IOException, ServletException {          logIt("RemulakServlet: setCustomerValueFromForm ");          CustomerValue custVal = new CustomerValue();          if (request.getParameter("customerId").length() > 0) {             logIt("RemulakServlet: My Length is " + request.getParameter("customerId").length());             logIt("RemulakServlet: My Value is " + request.getParameter("customerId"));             logIt("RemulakServlet: I Already Exist ");             Integer myCustId = new Integer(request.getParameter("customerId"));             custVal.setCustomerId(myCustId);          }          custVal.setCustomerNumber(request.getParameter("customerNumber"));          custVal.setPrefix(request.getParameter("prefix"));          custVal.setFirstName(request.getParameter("firstName"));          custVal.setMiddleInitial(request.getParameter("middleInitial"));          custVal.setLastName(request.getParameter("lastName"));          custVal.setSuffix(request.getParameter("suffix"));          custVal.setPhone1(request.getParameter("phone1"));          custVal.setPhone2(request.getParameter("phone2"));          custVal.setEMail(request.getParameter("eMail"));          return custVal;    }    /**     * sets parms from form into AddressValue object    */    private AddressValue setAddressValueFromForm(HttpServletRequest request)        throws IOException, ServletException {          logIt("RemulakServlet: setAddressValueFromForm ");          AddressValue addrVal = new AddressValue();          if (request.getParameter("addressId").length() > 0) {            Integer addressId = new Integer(request.getParameter("addressId"));            logIt("RemulakServlet: address id " + addressId);            addrVal.setAddressId(addressId);          }          logIt("RemulakServlet: no address ");          addrVal.setAddressLine1(request.getParameter("addressLine1"));          addrVal.setAddressLine2(request.getParameter("addressLine2"));          addrVal.setAddressLine3(request.getParameter("addressLine3"));          addrVal.setCity(request.getParameter("city"));          addrVal.setState(request.getParameter("state"));          addrVal.setZip(request.getParameter("zip"));          logIt("RemulakServlet: after address sets ");          return addrVal;    }    /**     * sets parms from form into CustomerValue for address add/update    */    private CustomerValue setAddrCustValueFromForm(HttpServletRequest request)        throws IOException, ServletException {          logIt("RemulakServlet: setAddrCustValueFromForm ");          CustomerValue custVal = new CustomerValue();          Integer customerId = new Integer(request.getParameter("customerId"));          custVal.setCustomerId(customerId);          custVal.setCustomerNumber(request.getParameter("customerNumber"));          return custVal;    }    /**     * sets parms from form into RoleValue object    */    private RoleValue setAddrRoleValueFromForm(HttpServletRequest request)        throws IOException, ServletException {          logIt("RemulakServlet: setAddrRoleValueFromForm ");          RoleValue roleVal = new RoleValue();          if (request.getParameter("addressId").length() > 0) {            Integer roleId = new Integer(request.getParameter("roleId"));            roleVal.setRoleId(roleId);          }          logIt("RemulakServlet: no address ");          roleVal.setRoleName(request.getParameter("roleName"));          return roleVal;    }    private static void logIt(String s) {    System.out.println(s);    }}

⌨️ 快捷键说明

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