How v-eenay/simple-servlet-gallery works
Main Components
• Frontend (View Layer):
• JSP pages (located under src/main/webapp/WEB-INF/view and its subdirectories)
• Static assets (CSS, JS in src/main/webapp/assets)
• Controllers (Presentation/Controller Layer):
• Servlets handling various user actions (LoginServlet, RegisterServlet, ImageDisplayServlet, etc. in the src/main/java/com/example/verysimpleimagegallery/controller and its admin sub-package)
• Business Logic / Service Layer:
• Service classes such as AuthService and GalleryService handling core business rules
• Data Access / Persistence Layer:
• DAO classes (GalleryItemDAO, UserDAO) for database interactions
• Database:
• Database connectivity via JDBC indicated by DbConnectionUtil and the configuration files (db.properties, schema.sql in src/main/resources)
• Utility Components:
• Utility classes like PasswordHashUtil for security (password handling)
• Filters:
• Authentication and authorization filters (AuthFilter, AdminAuthFilter) for managing access and session security
Relationships & Data Flow
a. A client's browser sends a request (via HTTP) and reaches the Frontend, typically beginning with a JSP rendered from the WEB-INF directory.
b. Requests are routed by the web.xml configuration to the appropriate Servlet controllers.
c. Controllers call methods from service classes (GalleryService, AuthService) to process business logic.
d. The service layer interacts with DAOs to perform database operations (CRUD via JDBC using DbConnectionUtil).
e. Results are passed back through the controller to a view (JSP) for rendering.
f. Filters (AuthFilter and AdminAuthFilter) are applied to requests to ensure proper security handling before controllers process them.
Highlighted Architectural Patterns & Design Principles
• MVC Pattern: Clearly differentiating between Model (Java objects in the model package), View (JSPs), and Controller (Servlets).
• DAO Pattern: Encapsulating database interaction in dedicated classes.
• Use of Filters for cross-cutting concerns like authentication (separation of concerns).
• RESTful Controllers: While this is a traditional servlet-based web app, the URI structure and request handling follow similar REST principles.
• Modularization: Splitting functionality into clear packages (controller, dao, service, model, util) helps with maintainability and scalability.
Technologies, Frameworks, and Tools
• Java Servlets & JSP: Core technologies for handling requests and dynamic page rendering.
• Apache Maven: Used for build automation (pom.xml, mvnw scripts).
• JDBC: For database connectivity.
• Apache Tomcat (or similar): As the deployed servlet container.
• Modern HTML/CSS and JavaScript: For the client-side, ensuring a responsive and interactive UI.