📄 remulakservlet.java
字号:
package com.jacksonreed;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;import java.util.*;import java.util.Properties;import javax.naming.Context;import javax.naming.InitialContext;import javax.naming.NamingException;/*** This is the main controller servlet for the Remulak Maintain* Relationships use case.* * In the Tomcat implemenation, only the Customer Add, Update, Delete* and inquiry function are implemented.** @author Paul Reed, Jackson-Reed, Inc. <prreed@jacksonreed.com>* @version 1.0*/public class RemulakServlet extends HttpServlet { private String url; public void init() throws ServletException { logIt("RemulakServlet: Init"); url = "t3://localhost:7001"; } public void destroy() { } /** * Processes a GET request by calling doPost(). */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { doPost(request, response); } /** * Performs the action specified by * the "action" request parameter. */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logIt("RemulakServlet: doPost"); String queryString = request.getQueryString(); logIt("RemulakServlet: querystring " + queryString); String action = request.getParameter("action"); logIt("RemulakServlet: action " + action.toString()); // Check which action to do and forward to it if ("Customer Inquiry".equals(action)) { doRltnCustomerInquiry(request, response); } else if ("New Customer".equals(action)) { logIt("RemulakServlet: switch to rltnCustomerNew "); doRltnCustomerNew(request, response); } else if ("Edit Customer".equals(action)) { doRltnCustomerEdit(request, response); } else if ("Delete Customer".equals(action)) { doRltnCustomerDelete(request, response); } else if ("Add/Update Customer".equals(action)) { doRltnCustomerAdd(request, response); } else if ("Edit Address".equals(action)) { doRltnAddressEdit(request, response); } else if ("Delete Address".equals(action)) { doRltnAddressDelete(request, response); } else if ("Add/Update Address".equals(action)) { doRltnAddressAdd(request, response); } else if ("Add Address".equals(action)) { doRltnAddressNew(request, response); } else { response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED); } } /** * This operation represents the relationship inquiry pathway through * the Maintain Relationships Use Case */ private void doRltnCustomerInquiry(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logIt("RemulakServlet: doRltnCustomerInquiry"); String customerNumber = request.getParameter("customerNumber"); logIt("RemulakServlet: request customer number " + customerNumber.toString()); if (customerNumber == null) { throw new ServletException("Missing customerNumber info"); } UCMaintainRltnshp UCController = new UCMaintainRltnshp(); // call to method in controller bean CustomerValue custVal = UCController.rltnCustomerInquiry(customerNumber); logIt("RemulakServlet: First Name " + custVal.getFirstName()); // set the custVal object into the Servlet Context so JSP's can see it request.setAttribute("custVal", custVal); // remove the UCMaintainRltnshp Controller logIt("Removing the Controller"); UCController = null; // Forward to the JSP page used to actually display the page forward("rltnInquiry.jsp", request, response); } /** * This operation represents the setup to add a customer pathway through * the Maintain Relationships Use Case */ private void doRltnCustomerNew(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logIt("RemulakServlet: doRltnCustomerNew"); CustomerValue custVal = new CustomerValue(); // set an empty 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 page forward("rltnCustomer.jsp", request, response); } /** * This operation represents the setup to edit a Customer * the Maintain Relationships Use Case */ private void doRltnCustomerEdit(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logIt("RemulakServlet: doRltnCustomerEdit"); String customerNumber = request.getParameter("customerNumber"); UCMaintainRltnshp UCController = new UCMaintainRltnshp(); // call to controller method in session bean CustomerValue custVal = UCController.rltnCustomerInquiry(customerNumber); logIt("RemulakServlet: First Name " + custVal.getFirstName()); logIt("RemulakServlet: Customer ID " + custVal.getCustomerId()); // set the custVal object into the Servlet Context so JSP's can see it request.setAttribute("custVal", custVal); // remove the UCMaintainRltnshp Controller logIt("Removing the Controller"); UCController = null; // Forward to the JSP page used to actually display the page forward("rltnCustomer.jsp", request, response); } /** * This operation represents the setup to add pathway through * the Maintain Relationships Use Case */ private void doRltnCustomerDelete(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logIt("RemulakServlet: doRltnCustomerDelete"); String custId = request.getParameter("customerId"); Integer customerId = new Integer(custId); logIt("RemulakServlet: customerId is " + customerId); UCMaintainRltnshp UCController = new UCMaintainRltnshp(); // call to controller method in session bean UCController.rltnDeleteCustomer(customerId); // remove the UCMaintainRltnshp Controller logIt("Removing the Controller"); UCController = null; // Send a redirect back to the home page response.sendRedirect("http://localhost:8080/RemulakWebApp/rltnEntry.html"); return; } /** * This operation represents the add and update customer pathways through * the Maintain Relationships Use Case */ private void doRltnCustomerAdd(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logIt("RemulakServlet: doRltnCustomerAdd"); UCMaintainRltnshp UCController = new UCMaintainRltnshp(); // Set the form values to a CustomerValue object CustomerValue custVal = setCustomerValueFromForm(request); // call to controller method in session bean to add or update the Customer if (request.getParameter("customerId").length() == 0) { logIt("RemulakServlet: Were adding"); UCController.rltnAddCustomer(custVal); //Add } else { UCController.rltnUpdateCustomer(custVal); //Update logIt("RemulakServlet: Were updating"); } custVal = UCController.rltnCustomerInquiry(custVal.getCustomerNumber()); //Requery logIt("RemulakServlet: doRltnCustomerAdd after controller call"); 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 doRltnAddressNew(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { logIt("RemulakServlet: doRltnAddressNew");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -