Hibernate and Struts 2 IntegrationWe can integrate any struts application with hibernate. There is no requirement of extra efforts. In this example, we going to use struts 2 framework with hibernate. You need to have jar files for struts 2 and hibernate. Example of Hibernate and struts2 integrationIn this example, we are creating the registration form using struts2 and storing this data into the database using Hibernate. Let's see the files that we should create to integrate the struts2 application with hibernate.
index.jspIn this page, we have created a form using the struts tags. The action name for this form is register. User.javaIt 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. RegisterDao.javaIt is a java class that saves the object of User class using the Hibernate framework. user.hbm.xmlThis mapping file contains all the information of the persitent class. hibernate.cfg.xmlThis configuration file contains informations about the database and mapping file. Here, we are using the hb2ddl.auto property, so you don't need to create the table in the database. struts.xmlThis files contains information about the action class to be invoked. Here the action class is User. welcome.jspIt is the welcome file, that displays the welcome message with username. <%@ taglib uri="/struts-tags" prefix="S" %> Welcome: <S:property value="name"/> web.xmlIt is web.xml file that contains the information about the controller. In case of Struts2, StrutsPrepareAndExecuteFilter class works as the controller. Next TopicHibernate and Spring Integration |