MVC Java 11 Web Application And Hibernate 5MVC Java 11 Web Application And Hibernate 5
Java Web Application with Hibernate 5, JSTL, and Bootstrap 4.5MVC Java 11 Web Application And Hibernate 5
Java Web Application with Hibernate 5, JSTL, and Bootstrap 4.5Overview
This project archetype is a template for creating a fully functional MVC web application using Hibernate, JSTL and Bootstrap. It has an automatic database creation, auto initial load of the data, with different variety of users. It also has a checkstyle to check the proper coding of your project immediately right after you enter the code.
Features
- Java 11+
- Maven 3+
- Hibernate 5
- JSTL
- Bootstrap 4.5
- Checkstyle for efficient coding
- Custom password encryption logic for secure system
- Support image database store
- Support any type of database server
Requirements
Knowledge Requirement:
- Java EE
- Hibernate
- JSTL
Software Requirements:
- Java v11+
- Maven v3+
- Apache Tomcat v9+
- Your database server of choice (Any DB server. i.e. PostgreSQL, SQLServer, Oracle, DB2, etc.)
- IDE of choice (Eclipse or IntelliJ)
Instructions
MVC Hibernate, JSTL, Bootstrap
Introduction:
This project archetype is a template for creating a fully functional MVC web application using Hibernate, JSTL and Bootstrap. It has an automatic database creation, auto initial load of the data, with different variety of users. It also has a checkstyle to check the proper coding of your project immediately right after you enter the code. This also has a custom encoder for password and not using the normal base64 encoder.
Requirements:
- Java v11+
- Maven v3+
- Apache Tomcat v9+
- Your database server of choice (Any DB server. i.e. PostgreSQL, SQLServer, Oracle, DB2, etc.)
- IDE of choice (Eclipse or IntelliJ)
Setup and Configuration:
- Download Java JDK.
- Download Maven.
- Download and configure database.
- Download Apache Tomcat
- Download and configure IDE
- Download the “MVC Hibernate JSTL Bootstrap” maven archetype
- Configure you default maven Installation and maven settings. Go to Windows à Preferences à Maven à Installations
- Set the maven as default maven installation.
- Select the settings.xml from the maven installation folder as the default global settings
- Configure Apache Tomcat Server, Under Windows à Preferences à Server à Runtime Environments, click Add button.
- Select Apache Tomcat v9.0 and check the “Create a new local server”.
- Select your tomcat installation folder and hit Finish button.
- Open your IDE and import “MVC Hibernate JSTL Bootstrap” archetype maven project
- Create new run configuration. Under Run à Run Configurations, Create new Maven Build.
- Set the name of the configuration, select the mvc-hibernate-jstl-bootstrap project and add the goal “clean package install”, then hit Apply and Run.
- Success! You can now create you template project from the new mvc-hibernate-jstl-bootstrap maven archetype.
Creating a web project:
- Create new maven project.
- Hit Next twice.
- Select the “mvc-hibernate-jstl-bootstrap” archetype.
- Set the following required fields:
- Group ID – Company name (i.e. com.sample)
- Artifact ID – Your project name (all small letter) (i.e. sample)
- Version – The initial version of the project (i.e. 1.0)
- contextPath – The default context path of your web project (i.e. sample)
- name – Name of the project to be display in the UI (i.e. Sample)
- description A short description of this project (i.e. Sample web application with Hibernate, JSTL and Bootstrap)
- 5 new projects should be created:
- sample – The parent project containing all the four projects.
- sample-beans – Base data model project, contains all the database table with hibernate annotation. (Model)
- sample-formbeans – Request/Response data model for the UI, consist of data model representation for web UI request and response. (View)
- sample-app – Main business logic project. Contains all the logic between the UI and the database.
- sample-ui – Web project, consist of servlets and jsp pages for the web application (Controller)
- Create new run configuration, under Run à Run Configuration, create new Maven Build. Enter the configuration name, Select the main project (in this case the “sample” project), then add “clean package install” as the Goals. Hit the Apply and Run button.
You should get the following logs:
- To be able to automatically create the tables in the database, you need to create the database and the user that has read/write access to create or drop the database tables and indexes. (If you are using PostgreSQL database, follow the instruction of creating the database below.)
- Go to Window à Show View à Servers, add the UI project in the server by right clicking into the server and click Add and Remove. Select the project then click “Add >”. Then hit Finish.
- Under the Project Explorer à Servers à , open catalina.properties.
- At the bottom of the file, add the following:
DB_CREATED=N
DEBUG_ENABLE=false
SHOW_SQL=false
ZONE=America/Winnipeg
#DATABASE_HOST_NAME=localhost
#DATABASE_PORT=5432
#DATABASE_NAME=sample
#DATABASE_USERNAME=sampleadm
#DATABASE_PASSWORD=sampleadm
- DB_CREATED à Y to create new database or N to update existing database
- DEBUG_ENABLE à true or false to enable debug
- SHOW_SQL à true or false to show sql queries in the logs
- ZONE à Your default timezone for localization
- DATABASE_HOST_NAME à the IP or hostname of the database server
- DATABASE_PORT à the port of the database server
- DATABASE_NAME à the name of the database
- DATABASE_USERNAME à the database user
- DATABASE_PASSWORD à the database user password
Note: Remove the “#” to uncomment the properties.
- Right click and start the server. By default, the database tables will be automatically created and an initial set of data will be loaded into the database.
- su/su à the Super User
- root/su à the Regular User
- member/su à the Member of the regular user
- You can access the website using this url: http://localhost:8080// (i.e., http://localhost:8080/sample/)
- Enjoy!!!
Creating a user and database on PostgreSQL:
- Open PGAdmin
- Under PostgreSQL , Right click on Login/Group Roles à Create à Login/Group Role.
- Enter the Name under the General tab and the password under the Definition tab. (in this case we use the same username and password for testing purposes, you can put whatever you like.)
- Under the Priveleges tab, set the following
- Can login? à YES
- Superuser? à NO
- Create roles? à NO
- Create databases? à YES
- Update catalogs? à NO
- Inherit rights from the parent roles? à YES
- Can initiate streaming replication and backups? NO
- Click the “Save” button.
- Right click on Databases à Create à Database
- Set the database name and select the new created user (i.e. sampleadm) as the owner. Then hist “Save” button.
Setup Project CheckStyle:
- Under Windows à Preferences, Select Checkstyle. Click the New button. Select External Configuration File for the Type, enter the name of the checkstyle and navigate to your parent project default folder and look for checkstyle.xml file.
- Select the new checkstyle as your default.
- On your projects (*-app, *.beans, *.ui), Right click and Properties. Check the “Checkstyle active for this project” and hit “Apply and Close”.
Category | Scripts & Code / Java |
First release | 2 January 2021 |
Last update | 5 January 2021 |
Files included | .html, .sql, .java, .xml, Javascript .js |
Database | MySQL 4.x, MySQL 5.x |
Tags | mvc |