In Java, SSH represents Struts, Spring, and Hibernate.
Struts resides in View and Controller layer (M-V-C), controls the display and dispatches the tasks. (View: Jsp, HTTP, Form, Tag, Resource; Controller: ActionServlet, struts-config.xml, and Action).
Hibernate: persistence layer framework, is a relational mapping tool in Java programming language.
Spring: a business logic layer framework.
1. Traditional Java Web Application
Before Struts framework, Java Web applies
JSP+Servlet+JavaBean to implement. It implies the
MVC framework, where JSP is in
Servlet implements the business logic, and
JavaBean encapsulate the data entity. My project
SaskShare AI Platform follows this architecture to build.
But the problems are obvious. In JSP files, there are lots of Java code embedded, which messes up the page structure. While Servlet redirecting pages and JavaBeans doing the logic calculation makes the program hard to reuse, and modules coupled together.
2. Then Struts
In Struts, we only need an
Action class to act as the
Controller. The Action class responds to a user action. In JSP, there are lots of Struts provided tags available. Therefore, JSP code is clean. But still,
Action needs to call business code to implement the business logic. And
Business layers call the
persistence layer for retrieving the data.
Hibernate is an Object/Relation Mapping Solution for Java environments. Here Object/Relation Mapping refers to the technique of mapping data between an object model representation to a relational database model representation.
Instead of writing
SQL statement, hibernate allows us only focus on the Persistent class. Create the mapping relation, and operate persistent class.
But still, you will have to
new the business class so that Struts can invoke it. As well as in
new the DAO impl class. This will cause the strong coupling among those layers. Therefore,
Spring is emerging.
Spring is used to decouple the dependency among classes. The core feature of Spring is Dependency Injection, and IoC.
The popular Java Web Application is “SSH”. Struts is responsible for presentation, Hibernate is responsible for Persistence, while Spring for Business Logic.
Spring has a big family, which includes
Spring Cloud Data Flow,
Spring Integration, and much more. Keep yourself learning, and you can make yourself forward.