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 -
Method Summary
Modifier and TypeMethodDescriptionprotected 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
-
Constructor Details
-
CustomerServlet
public CustomerServlet()
-
-
Method Details
-
getDataStorage
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 responsesuccess
- whether the operation was successfulmessage
- the response messagedata
- 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 classjavax.servlet.http.HttpServlet
- Parameters:
request
- the HTTP servlet requestresponse
- the HTTP servlet response- Throws:
javax.servlet.ServletException
- if a servlet error occursIOException
- 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 classjavax.servlet.http.HttpServlet
- Parameters:
request
- the HTTP servlet requestresponse
- the HTTP servlet response- Throws:
javax.servlet.ServletException
- if a servlet error occursIOException
- if an I/O error occurs
-