Package servlet

Class CustomerServlet

java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
servlet.CustomerServlet
All Implemented Interfaces:
Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

@WebServlet("/customer") public class CustomerServlet extends javax.servlet.http.HttpServlet
Servlet that handles all customer related operations. Manages customer retrieval, updates, and deletion with role based access control.
Author:
TAMIL MUGHILAN
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handles GET requests for customer retrieval operations.
    protected void
    doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    Handles POST requests for customer modification operations.
    private DataStorage
    getDataStorage(String storageType)
    Gets the appropriate data storage implementation based on storage type.
    private void
    sendJsonResponse(javax.servlet.http.HttpServletResponse response, boolean success, String message, Object data)
    Sends JSON response for AJAX requests.

    Methods inherited from class javax.servlet.http.HttpServlet

    doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service

    Methods inherited from class javax.servlet.GenericServlet

    destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CustomerServlet

      public CustomerServlet()
  • Method Details

    • getDataStorage

      private DataStorage getDataStorage(String storageType) throws SQLException
      Gets the appropriate data storage implementation based on storage type.
      Parameters:
      storageType - the type of storage (database, collection, mongodb)
      Returns:
      the data storage implementation
      Throws:
      SQLException - if database connection fails
    • sendJsonResponse

      private void sendJsonResponse(javax.servlet.http.HttpServletResponse response, boolean success, String message, Object data) throws IOException
      Sends JSON response for AJAX requests.
      Parameters:
      response - the HTTP response
      success - whether the operation was successful
      message - the response message
      data - the response data
      Throws:
      IOException - if writing response fails
    • doGet

      protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
      Handles GET requests for customer retrieval operations. Performs Dependency Injection by passing the user's choice of data storage into the Services. Viewing customers by ID, email, and branch.
      Overrides:
      doGet in class javax.servlet.http.HttpServlet
      Parameters:
      request - the HTTP servlet request
      response - the HTTP servlet response
      Throws:
      javax.servlet.ServletException - if a servlet error occurs
      IOException - if an I/O error occurs
    • doPost

      protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException
      Handles POST requests for customer modification operations. Performs customer updates and deletion with proper authorization.
      Overrides:
      doPost in class javax.servlet.http.HttpServlet
      Parameters:
      request - the HTTP servlet request
      response - the HTTP servlet response
      Throws:
      javax.servlet.ServletException - if a servlet error occurs
      IOException - if an I/O error occurs