Servlet Starter Kit - Modern Java Web Starter Project

Servlet Starter Kit is a complete starter toolkit for Java Web application development, designed specifically for educational purposes. The project combines the most modern Java EE technologies with a beautiful user interface, allowing students and new developers to learn and build web applications quickly.
The project is organized according to the standard MVC (Model-View-Controller) pattern, making the code easy to maintain and extend:
BaseWebController and BaseAjaxController provide shared utility methods.The Page class offers a modern approach to rendering views:
1Page page = new Page()
2 .setTitle("Home Page")
3 .setPageName("home/index")
4 .setLayout("app")
5 .setScripts(new String[]{"user-management.js"})
6 .setStyleSheets(new String[]{"custom.css"});
7
8page.render(request, response);Advantages:
JDBI Integration
1@ApplicationScoped
2public class UserRepository extends BaseRepository<User, Long> implements IUserRepository {
3 // Inherits all CRUD operations from BaseRepository
4}
5Auto Database Migration
schema_migrations table.1@WebListener
2public class DatabaseMigrationListener implements ServletContextListener {
3 // Auto-run migrations on startup
4}UI Features:
A fully functional user management module including:
1@WebServlet("/ajax/users/*")
2public class AjaxUserController extends BaseAjaxController {
3 // Handles create, update, delete, activate, deactivate
4}Utilities Classes
PropertiesUtils: Reads configuration from properties files.WebAppPaths: Manages paths for static resources and views.BaseModelMapper: Automatically maps database rows to objects.Filters
JsCharsetFilter: Ensures UTF-8 encoding for JavaScript files.Dependency Injection
@Inject annotation for dependency injection.@ApplicationScoped beans.The project uses properties files for configuration:
1# Database Configuration
2db.driver=org.h2.Driver
3db.url=jdbc:h2:~/servlet-kit-db
4db.username=sa
5db.password=
6db.name=app_db
71./mvnw clean packageservlet-starter-kit/
├── src/main/
│ ├── java/com/nphuonha/servletkit/
│ │ ├── core/ # Core utilities
│ │ │ ├── database/ # DB connection, migrations
│ │ │ ├── listeners/ # Servlet listeners
│ │ │ ├── paths/ # Path management
│ │ │ └── utils/ # Utility classes
│ │ ├── http/
│ │ │ ├── controllers/ # Web & AJAX controllers
│ │ │ ├── filters/ # Request filters
│ │ │ └── pages/ # Page rendering
│ │ ├── models/ # Domain models
│ │ ├── repository/ # Data access layer
│ │ └── services/ # Business logic
│ ├── resources/
│ │ ├── migrations/ # SQL migration files
│ │ └── application.properties
│ └── webapp/
│ ├── static/ # CSS, JS, images
│ └── views/ # JSP templates
│ ├── layouts/ # Layout templates
│ └── pages/ # Page views
├── pom.xml
├── tailwind.config.js
└── package.json
This project is suitable for:
Backend:
Frontend:
Build Tools:
Disclaimer: This project is designed for educational purposes. It should not be used directly in production without a thorough security review and optimization.
Repository: nphuonha2101/servlet-starter-kit