Hibernate and Struts Integration Example Tutorial

We can incorporate any struts application with hibernate. There is no prerequisite of additional endeavors.

In this model, we going to utilize swaggers 2 system with rest. You need container records for swaggers 2 and sleep.

Example of Hibernate and struts2 integration

In this model, we are making the enlistment structure utilizing struts2 and putting away this information into the database utilizing Hibernate. How about we see the documents that we ought to make to incorporate the struts2 application with hibernate.

  • index.jsp record to get contribution from the user.
  • User.java An activity class for dealing with the solicitation. It utilizes the dao class to store the data.
  • RegisterDao.java A java class that utilizes DAO configuration example to store the information utilizing hibernate.
  • user.hbm.xml A mapping document that contains data about the tenacious class. For this situation, activity class fills in as the constant class.
  • hibernate.cfg.xml An arrangement record that contains informations about the database and mapping file.
  • struts.xml document contains data about the activity class and result page to be invoked.
  • welcome.jsp A jsp document that shows the appreciated data with username.
  • web.xml A web.xml document that contains data about the Controller of Struts framework.


In this page, we have created a form using the struts tags. The action name for this form is register.

  1. <%@ taglib uri="/struts-tags" prefix="S" %>  
  3. <S:form action="register">  
  4. <S:textfield name="name" label="Name"></S:textfield>  
  5. <S:submit value="register"></S:submit>  
  7. </S:form>  


It is a simple POJO class. Here it works as the action class for struts and persistent class for hibernate. It calls the register method of RegisterDao class and returns success as the string.

  1. package com.javacodegeeks;  
  3. public class User {  
  4. private int id;  
  5. private String name;  
  6. //getters and setters  
  8. public String execute(){  
  9.     RegisterDao.saveUser(this);  
  10.     return "success";  
  11. }  
  13. }  


javacodegeeks is optimized for learning.© javacodegeeks .
All Right Reserved and you agree to have read and accepted our term and condition