Package servlet
Class AccountServlet
java.lang.Object
javax.servlet.GenericServlet
javax.servlet.http.HttpServlet
servlet.AccountServlet
- All Implemented Interfaces:
Serializable
,javax.servlet.Servlet
,javax.servlet.ServletConfig
@WebServlet("/account")
public class AccountServlet
extends javax.servlet.http.HttpServlet
Servlet that handles all account related operations.
Manages account creation, transactions, joint accounts, and transaction history.
Supports multiple storage types.
- 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 account retrieval operations.protected void
doPost
(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) Handles POST requests for account modification operations.private Integer
getCurrentUserId
(javax.servlet.http.HttpServletRequest request) Gets the current user's ID from session.private TransactionLog.UserType
getCurrentUserType
(javax.servlet.http.HttpServletRequest request) Gets the current user's type from session.private DataStorage
getDataStorage
(String storageType) Gets the correct data storage implementation based on storage type.private void
sendAccountsJsonResponse
(javax.servlet.http.HttpServletResponse response, boolean success, String message, List<SavingsAccount> accounts) Sends JSON response for account data.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
-
AccountServlet
public AccountServlet()
-
-
Method Details
-
getDataStorage
Gets the correct data storage implementation based on storage type.- Parameters:
storageType
- the type of storage (database, collections, mongoDB)- Returns:
- the data storage implementation
- Throws:
SQLException
- if database connection fails
-
getCurrentUserId
Gets the current user's ID from session.- Parameters:
request
- the HTTP request- Returns:
- the user ID or null if not found
-
getCurrentUserType
Gets the current user's type from session.- Parameters:
request
- the HTTP request- Returns:
- the user type (CUSTOMER, EMPLOYEE, MANAGER) or null
-
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
-
sendAccountsJsonResponse
private void sendAccountsJsonResponse(javax.servlet.http.HttpServletResponse response, boolean success, String message, List<SavingsAccount> accounts) throws IOException Sends JSON response for account data.- Parameters:
response
- the HTTP responsesuccess
- whether the operation was successfulmessage
- the response messageaccounts
- list of accounts to include in response- 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 account retrieval operations. Performs Dependency Injection by passing the user's choice of data storage into the Services. Viewing accounts by ID, branch, customer, and transaction history.- 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 account modification operations. Performs Dependency Injection by passing the user's choice of data storage into the Services. Account creation, deposits, withdrawals, and joint account management.- 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
-