<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<p>In this example we will describe the integration of Struts 2 with Hibernate as well as using Spring and Tile in this example. We recommend firstly you have a look to previous examples <b><a href="https://dineshonjava.com/struts2-spring-3-integration-example/" target="_blank" rel="noopener">Struts with Spring Integration Example</a></b> and <b><a href="https://dineshonjava.com/struts2-integration-with-tiles2-spring3/" target="_blank" rel="noopener">Struts2 with Tiles2 Integration Example</a></b>.</p>
<h2 dir="ltr">Spring 5 Design Pattern Book</h2>
<div dir="ltr" style="color: #20124d; font-family: 'calibri' , sans-serif; font-size: 13pt; text-align: justify;">You could purchase my <strong>Spring 5 book</strong> that is with title name &#8220;<strong>Spring 5 Design Pattern</strong>&#8220;. This book is available on the <a href="https://www.amazon.in/Spring-Design-Patterns-Dinesh-Rajput/dp/1788299450/ref=sr_1_1?ie=UTF8&;qid=1507925340&;sr=8-1&;keywords=spring+5+design+pattern" target="_blank" rel="noopener"><strong>Amazon</strong></a> and <a href="https://www.packtpub.com/application-development/spring-5-design-patterns" target="_blank" rel="noopener"><strong>Packt</strong></a> publisher website. Learn various <strong>design patterns</strong> and <strong>best practices</strong> in Spring 5 and use them to solve common design problems. You could use author discount to purchase this book by using code- &#8220;<strong>AUTHDIS40</strong>&#8220;.</div>
<div dir="ltr"></div>
<div dir="ltr"><a href="https://www.packtpub.com/application-development/spring-5-design-patterns" target="_blank" rel="noopener"><img class="aligncenter wp-image-3053 size-medium" title="Spring-5-Design-Pattern" src="https://dineshonjava.com/wp-content/uploads/2013/03/Spring-5-design-pattern-243x300.jpg" width="243" height="300" /></a></div>
<p>Hibernate is a high-performance Object/Relational persistence and query service which is licensed under the open source GNU Lesser General Public License (LGPL) and is free to download. If you are not familiar with Hibernate then you can check our <b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/" target="_blank" rel="noopener">Hibernate tutorial</a></b>. And if you are not familiar with Spring then you can check our <b><a href="https://dineshonjava.com/spring-tutorial/" target="_blank" rel="noopener">Spring tutorial</a></b>.</p>
<h2>Step 1: Create a Database DOJDB on MySQL Database and also we create User table on this database.</h2>
<pre class="highlight">CREATE TABLE User( 
 ID BIGINT NOT NULL AUTO_INCREMENT, 
 USERNAME VARCHAR(20) NOT NULL, 
 AGE BIGINT NOT NULL, 
 GENDER VARCHAR(20) NOT NULL, 
 JOBTYPE VARCHAR(20) NOT NULL 
 HOBBIES VARCHAR(20) NOT NULL 
 PRIMARY KEY (ID) 
); 
</pre>
<p><b>Step 2: Create a database.properties for database configuration information in the resources folder under src folder in the created project.</b></p>
<pre class="highlight">database.driver=com.mysql.jdbc.Driver 
database.url=jdbc:mysql://localhost:3306/DOJDB 
database.user=root 
database.password=root 
hibernate.dialect=org.hibernate.dialect.MySQLDialect 
hibernate.show_sql=true 
hibernate.hbm2ddl.auto=update 
</pre>
<p><b>Step 3: </b>Create a Dynamic Web Project with a name <b><i>Struts2Hibernate3Spring3Tile2Integration </i></b>and create packages <i>com.dineshonjava.struts2.action, com.dineshonjava.struts2.bean, com.dineshonjava.struts2.dao, com.dineshonjava.struts2.service, com.dineshonjava.struts2.model, com.dineshonjava.struts2.utils</i> under the <i>src </i>folder in the created project.</p>
<p><b>Step 4: </b>Add below mentioned Struts 2, Hibernate 3 and Spring 3 related libraries and other libraries into the folder <i><b>WebRoot/WEB-INF/lib</b></i>.</p>
<div class="separator" style="clear: both; text-align: center;"><img src="http://dineshonjava.com/wp-content/uploads/2013/08/66666.png" border="0" /></div>
<p><b>Step 5:</b> Create a Java class <b>UserAction</b>, <b>UserBean</b>, <b>User</b>, <b>UserDao</b>, <b>UserDaoImpl</b>, <b>UserService</b>, <b>UserServiceImpl</b>, <b>CommonUtility </b>under the respective packages.</p>
<p><b>Step 6: </b>Create Spring configuration files <i><b>web.xml, applicationContext.xml, tiles-def.xml </b></i>under the <i>WebRoot/WEB-INF/</i> and <b>struts.xml </b>under <i><b>src/resources</b></i> folders.</p>
<p><b>Step 7: </b>Create View files under the<b> /WebRoot/</b> folder. Create a view file <b><i>mainTemplate.jsp, users.jsp, body.jsp, menu.jsp, haeder.jsp, footer.jsp </i></b> etc.</p>
<p><b>Step 8: Project Structure </b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="http://dineshonjava.com/wp-content/uploads/2013/08/7777.png" border="0" /></div>
<h2><b>APPLICATION ARCHITECTURE</b></h2>
<p>We will have a layered architecture for our demo application. The database will be accessed by a Data Access layer popularly called as DAO Layer. This layer will use Hibernate API to interact with database. The DAO layer will be invoked by a service layer. In our application we will have a Service interface called UserService.</p>
<div class="separator" style="clear: both; text-align: center;"><img src="http://dineshonjava.com/wp-content/uploads/2013/08/spring3-hibernate-application-architecture-with-tiles.png" border="0" /></div>
<p><b>Step 9: </b>Hibernate Configuration file with Spring Dependencies<br />
<i><b>applicationContext.xml</b></i></p>
<pre class="highlight"><;?xml version="1.0" encoding="UTF-8"?>; 
<;beans xmlns="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xmlns:context="http://www.springframework.org/schema/context" 
 xmlns:tx="http://www.springframework.org/schema/tx" 
 xsi:schemaLocation=" 
http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context-3.0.xsd 
http://www.springframework.org/schema/tx 
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">; 
 
 <;context:component-scan base-package="com.dineshonjava.struts2" />; 
 
 <;!-- Database Configuration Start here-->; 
 <;context:property-placeholder location="classpath:database.properties"/>; 
 <;tx:annotation-driven transaction-manager="hibernateTransactionManager"/>; 
 <;bean class="org.springframework.jdbc.datasource.DriverManagerDataSource" id="dataSource">; 
 <;property name="driverClassName" value="${database.driver}">;<;/property>; 
 <;property name="url" value="${database.url}">;<;/property>; 
 <;property name="username" value="${database.user}">;<;/property>; 
 <;property name="password" value="${database.password}">;<;/property>; 
 <;/bean>; 
 <;bean class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" id="sessionFactory">; 
 <;property name="dataSource" ref="dataSource">;<;/property>; 
 <;property name="annotatedClasses">; 
 <;list>; 
 <;value>;com.dineshonjava.struts2.model.User<;/value>; 
 <;/list>; 
 <;/property>; 
 <;property name="hibernateProperties">; 
 <;props>; 
 <;prop key="hibernate.dialect">;org.hibernate.dialect.MySQLDialect<;/prop>; 
 <;prop key="hibernate.show_sql">;${hibernate.show_sql}<;/prop>; 
 <;prop key="hibernate.hbm2ddl.auto">;${hibernate.hbm2ddl.auto} <;/prop>; 
 <;/props>; 
 <;/property>; 
 <;/bean>; 
 
 <;bean class="org.springframework.orm.hibernate3.HibernateTransactionManager" id="hibernateTransactionManager">; 
 <;property name="sessionFactory" ref="sessionFactory">;<;/property>; 
 <;/bean>; 
 <;!-- Database Configuration End Here-->; 
 
 
 <;bean id="user" class="com.dineshonjava.struts2.action.UserAction"/>; 
 <;bean id="userBean" class="com.dineshonjava.struts2.bean.UserBean"/>; 
<;/beans>; 
</pre>
<p>Let us go through the hibernate configuration only because rest is Spring dependency already know in <b><a href="https://dineshonjava.com/2012/06/spring-30-baby-step-to-learn.html" target="_blank" rel="noopener">spring tutorial</a></b>. First, we declared that we are using MySQL driver. Then we declared the jdbc url for connecting to the database. Then we declared the connection&#8217;s username, password and pool size. We also indicated that we would like to see the SQL in the log file by turning on &#8220;show_sql&#8221; to true. Please go through the hibernate tutorial to understand what these properties mean. Finally, we set the mapping class to <i><b>com.dineshonjava.struts2.model.User </b></i>which we will create in this chapter.</p>
<p><b>Step 10: </b>Create Action class and Other classes related to Application.<br />
<b>UserBean.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.bean; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public class UserBean { 
 private String userName; 
 private Long userAge; 
 private String userGender; 
 private String userJob; 
 private String []userHobbies; 
 public String getUserName() { 
 return userName; 
 } 
 public void setUserName(String userName) { 
 this.userName = userName; 
 } 
 public Long getUserAge() { 
 return userAge; 
 } 
 public void setUserAge(Long userAge) { 
 this.userAge = userAge; 
 } 
 public String getUserGender() { 
 return userGender; 
 } 
 public void setUserGender(String userGender) { 
 this.userGender = userGender; 
 } 
 public String getUserJob() { 
 return userJob; 
 } 
 public void setUserJob(String userJob) { 
 this.userJob = userJob; 
 } 
 public String[] getUserHobbies() { 
 return userHobbies; 
 } 
 public void setUserHobbies(String[] userHobbies) { 
 this.userHobbies = userHobbies; 
 } 
} 
</pre>
<p><b>User.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.model; 
 
import java.io.Serializable; 
 
import javax.persistence.Column; 
import javax.persistence.Entity; 
import javax.persistence.GeneratedValue; 
import javax.persistence.GenerationType; 
import javax.persistence.Id; 
import javax.persistence.Table; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@Entity 
@Table(name="User") 
public class User implements Serializable { 
 
 private static final long serialVersionUID = 1L; 
 
 @Id 
 @GeneratedValue(strategy=GenerationType.AUTO) 
 @Column(name = "id") 
 private Long userId; 
 @Column(name="username") 
 private String userName; 
 @Column(name="age") 
 private Long userAge; 
 @Column(name="gender") 
 private String userGender; 
 @Column(name="jobtype") 
 private String userJobType; 
 @Column(name="Hobbies") 
 private String userHobbies; 
 public Long getUserId() { 
 return userId; 
 } 
 public void setUserId(Long userId) { 
 this.userId = userId; 
 } 
 public String getUserName() { 
 return userName; 
 } 
 public void setUserName(String userName) { 
 this.userName = userName; 
 } 
 public Long getUserAge() { 
 return userAge; 
 } 
 public void setUserAge(Long userAge) { 
 this.userAge = userAge; 
 } 
 public String getUserGender() { 
 return userGender; 
 } 
 public void setUserGender(String userGender) { 
 this.userGender = userGender; 
 } 
 public String getUserJobType() { 
 return userJobType; 
 } 
 public void setUserJobType(String userJobType) { 
 this.userJobType = userJobType; 
 } 
 public String getUserHobbies() { 
 return userHobbies; 
 } 
 public void setUserHobbies(String userHobbies) { 
 this.userHobbies = userHobbies; 
 } 
} 
</pre>
<p><b>UserDao.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.dao; 
 
import java.util.List; 
 
import com.dineshonjava.struts2.model.User; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public interface UserDao { 
 void saveUser(User user); 
 
 List<;User>; getUserList(); 
} 
</pre>
<p><b>UserDaoImpl.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.dao; 
 
import java.util.List; 
 
import org.hibernate.SessionFactory; 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Repository; 
 
import com.dineshonjava.struts2.model.User; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@Repository("userDao") 
public class UserDaoImpl implements UserDao { 
 
 @Autowired 
 private SessionFactory sessionFactory; 
 
 @Override 
 public void saveUser(User user) { 
 sessionFactory.getCurrentSession().saveOrUpdate(user); 
 } 
 
 @SuppressWarnings("unchecked") 
 @Override 
 public List<;User>; getUserList() { 
 return (List<;User>;) sessionFactory.getCurrentSession().createCriteria(User.class).list(); 
 } 
} 
</pre>
<p><b>UserService.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.service; 
 
import java.util.List; 
 
import com.dineshonjava.struts2.model.User; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public interface UserService { 
 void saveUser(User user); 
 
 List<;User>; getUserList(); 
} 
 
</pre>
<p><b>UserServiceImpl.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.service; 
 
import java.util.List; 
 
import org.springframework.beans.factory.annotation.Autowired; 
import org.springframework.stereotype.Service; 
import org.springframework.transaction.annotation.Propagation; 
import org.springframework.transaction.annotation.Transactional; 
 
import com.dineshonjava.struts2.dao.UserDao; 
import com.dineshonjava.struts2.model.User; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@Service("userService") 
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true) 
public class UserServiceImpl implements UserService { 
 
 @Autowired 
 private UserDao userDao; 
 
 @Override 
 @Transactional(propagation = Propagation.REQUIRED, readOnly = false) 
 public void saveUser(User user) { 
 userDao.saveUser(user); 
 } 
 
 @Override 
 public List<;User>; getUserList() { 
 return userDao.getUserList(); 
 } 
} 
</pre>
<p><b>CommonUtility.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.utils; 
 
import java.util.ArrayList; 
import java.util.List; 
 
import com.dineshonjava.struts2.bean.UserBean; 
import com.dineshonjava.struts2.model.User; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public class CommonUtility { 
 public static User createModel(UserBean userBean){ 
 User user = new User(); 
 user.setUserName(userBean.getUserName()); 
 user.setUserAge(userBean.getUserAge()); 
 user.setUserGender(userBean.getUserGender()); 
 user.setUserJobType(userBean.getUserJob()); 
 user.setUserHobbies(convertArrayToCsv(userBean.getUserHobbies())); 
 return user; 
 } 
 
 public static List<;UserBean>; createUserBeanList(List<;User>; users){ 
 List<;UserBean>; beans = new ArrayList<;UserBean>;(); 
 UserBean userBean = null; 
 for(User user : users){ 
 userBean = new UserBean(); 
 userBean.setUserName(user.getUserName()); 
 userBean.setUserAge(user.getUserAge()); 
 userBean.setUserGender(user.getUserGender()); 
 userBean.setUserJob(user.getUserJobType()); 
 userBean.setUserHobbies(convertCsvToArr(user.getUserHobbies())); 
 beans.add(userBean); 
 } 
 return beans; 
 
 } 
 public static String convertArrayToCsv(String [] arr){ 
 String csv = ""; 
 for(String value : arr){ 
 csv += value+","; 
 } 
 return csv; 
 } 
 public static String[] convertCsvToArr(String csv){ 
 String [] values = csv.split(","); 
 return values; 
 } 
} 
</pre>
<p><b>UserAction.java</b></p>
<pre class="highlight">package com.dineshonjava.struts2.action; 
 
import java.util.ArrayList; 
import java.util.List; 
 
import org.springframework.beans.factory.annotation.Autowired; 
 
import com.dineshonjava.struts2.bean.UserBean; 
import com.dineshonjava.struts2.model.User; 
import com.dineshonjava.struts2.service.UserService; 
import com.dineshonjava.struts2.utils.CommonUtility; 
import com.opensymphony.xwork2.ActionSupport; 
import com.opensymphony.xwork2.ModelDriven; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public class UserAction extends ActionSupport implements ModelDriven<;UserBean>;{ 
 
 private static final long serialVersionUID = 1L; 
 
 @Autowired 
 private UserBean userBean; 
 @Autowired 
 private UserService userService; 
 private List<;UserBean>; users; 
 
 public String execute() { 
 users = CommonUtility.createUserBeanList(userService.getUserList()); 
 return "user"; 
 } 
 
 public String addUser(){ 
 userService.saveUser(CommonUtility.createModel(userBean)); 
 users = CommonUtility.createUserBeanList(userService.getUserList()); 
 return "addUser"; 
 } 
 public String listUser(){ 
 users = CommonUtility.createUserBeanList(userService.getUserList()); 
 return "users"; 
 } 
 
 @Override 
 public UserBean getModel() { 
 return userBean; 
 } 
 public String alia() { 
 return "alia"; 
 } 
 public String madhuri() { 
 return "madhuri"; 
 } 
 public String user() { 
 return "user"; 
 } 
 
 public List<;UserBean>; getUsers() { 
 return users; 
 } 
 
 public void setUsers(List<;UserBean>; users) { 
 this.users = users; 
 } 
 
} 
</pre>
<p><b>Create view files:</b><br />
Let us now create the <i><b>mainTemplate.jsp </b></i>view file with the following content:</p>
<pre class="highlight"><;%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>; 
<;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
 "http://www.w3.org/TR/html4/loose.dtd">; 
<;html>; 
 
<;head>; 
<;meta http-equiv="Content-Type" content="text/html; charset=UTF-8">; 
<;title>;<;tiles:insertAttribute name="title" ignore="true">;<;/tiles:insertAttribute>; 
<;/title>; 
<;/head>; 
 
<;body>; 
 <;table border="1">; 
 <;tr>; 
 <;td colspan="2">;<;tiles:insertAttribute name="header">;<;/tiles:insertAttribute>;<;br/>;<;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td>;<;tiles:insertAttribute name="menu" />;<;/td>; 
 <;td>;<;tiles:insertAttribute name="body" />;<;/td>; 
 <;/tr>; 
 <;tr>; 
 <;td colspan="2">;<;tiles:insertAttribute name="footer" />;<;/td>; 
 <;/tr>; 
 <;/table>; 
<;/body>; 
<;/html>; 
</pre>
<p><b>body.jsp</b></p>
<pre class="highlight"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
<;%@ taglib prefix="s" uri="/struts-tags"%>; 
<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">; 
 
<;html>; 
<;head>; 
<;style type="text/css">; 
b{color:navy; background-color: orange;} 
<;/style>; 
<;title>;Struts2-Spring-Tiles integration | dineshonjava.com<;/title>; 
<;/head>; 
<;body>; 
 
 <;h2>;Add User<;/h2>;<;b>; 
 <;s:form action="addUsermenu">; 
 <;s:textfield name="userName" key="user.name" />; 
 <;s:textfield name="userAge" key="user.age" value=""/>; 
 <;s:radio name="userGender" key="user.gender" list="{'Male','Female'}" />; 
 <;s:select name="userJob" key="user.job" list="%{#{'Software':'Software','Hardware':'Hardware','Networking':'Networking','Marketing':'Marketing'}}"/>; 
 <;s:checkboxlist name="userHobbies" key="user.hobby" list="{'Cricket','Football','Drawing','Cooking','Driving','Movie'}" />; 
 <;s:submit key="submit" align="center"/>; 
 <;/s:form>; 
 <;/b>; 
 <;s:if test="%{users.isEmpty()}">; 
 <;/s:if>; 
 <;s:else>; 
 <;b>;List of Users<;/b>; 
 <;table border="1">; 
 <;tr>; 
 <;td>;<;b>;Name<;/b>;<;/td>; 
 <;td>;<;b>;Age<;/b>;<;/td>; 
 <;td>;<;b>;Gender<;/b>;<;/td>; 
 <;td>;<;b>;Job Type<;/b>;<;/td>; 
 <;td>;<;b>;Hobbies<;/b>;<;/td>; 
 <;/tr>; 
 <;s:iterator value="users">; 
 <;tr>; 
 <;td>;<;s:property value="userName"/>;<;/td>; 
 <;td>;<;s:property value="userAge"/>;<;/td>; 
 <;td>;<;s:property value="userGender"/>;<;/td>; 
 <;td>;<;s:property value="userJob"/>;<;/td>; 
 <;td>;<;s:property value="userHobbies"/>;<;/td>; 
 <;/tr>; 
 <;/s:iterator>; 
 <;/table>; 
 <;/s:else>; 
 <;/body>; 
<;/html>; 
</pre>
<p><b>menu.jsp</b></p>
<pre class="highlight"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
<;%@ taglib prefix="s" uri="/struts-tags"%>; 
 <;a href="<;s:url action="usermenu"/>;">; <;h2>;Add User<;/h2>;<;/a>;<;br>; 
 <;a href="<;s:url action="aliamenu"/>;">;<;h2>;Alia Bhatt<;/h2>;<;/a>;<;br>; 
 <;a href="<;s:url action="madhurimenu"/>;">;<;h2>;Madhuri Dixit<;/h2>;<;/a>;<;br>; 
 
</pre>
<p><b>footer.jsp</b></p>
<pre class="highlight"><;center>;<;p>;<;h2>;Copyright &;copy; 2013 dineshonjava.com<;/h2>;<;/p>; <;/center>; 
 
</pre>
<p><b>header.jsp</b></p>
<pre class="highlight"><;table>; 
 <;tr>; 
 <;td>;<;img src="http://2.bp.blogspot.com/-rBLnvKuVDO0/UWBnJJ4n1yI/AAAAAAAADCQ/Vh_cVJ34JFw/s1600/new-logo.png" />;<;/td>; 
 <;td>;<;h1>;<;span style="background-color: #FFFFcc">;Struts2-Hibernate3-Tiles2-Spring3 integration<;/span>;<;/h1>;<;/td>; 
 <;/tr>; 
<;/table>; 
</pre>
<p><b>users.jsp</b></p>
<pre class="highlight"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
<;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">; 
<;html>; 
<;head>; 
<;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">; 
<;title>;Insert title here<;/title>; 
<;/head>; 
<;body>; 
 <;a href="user">;Struts2Spring3Hibernate3Tiles Example<;/a>; 
<;/body>; 
<;/html>; 
</pre>
<p><b>madhuri.jsp</b></p>
<pre class="highlight"><;img src="http://www.topnews.in/files/Madhuri-Dixit_10.jpg" height="430" width="500" alt="Madhuri Dixit"/>; 
 
</pre>
<p><b>alia.jsp</b></p>
<pre class="highlight"><;img src="http://cdntopics.onepakistan.com/wp-content/uploads/2012/10/Alia-Bhatt1.jpg" alt="Alia Bhatt"/>; 
</pre>
<p><b>Struts Configuration:</b><br />
Let us put it all together using <b><i>struts.xml</i></b>:</p>
<pre class="highlight"><;?xml version="1.0" encoding="UTF-8" ?>; 
<;!DOCTYPE struts PUBLIC 
 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
 "http://struts.apache.org/dtds/struts-2.0.dtd">; 
 
<;struts>; 
 <;constant name="struts.enable.DynamicMethodInvocation" value="false" />; 
 <;constant name="struts.devMode" value="true" />; 
 <;constant name="struts.custom.i18n.resources" value="myapp" />; 
 
 <;package name="user" extends="struts-default" namespace="/">; 
 <;result-types>; 
 <;result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />; 
 <;/result-types>; 
 <;action name="user" class="user" method="execute">; 
 <;result name="user" type="tiles">;mainTemplate<;/result>; 
 <;/action>; 
 <;action name="*menu" class="user" method="{1}">; 
 <;result name="user" type="tiles">;mainTemplate<;/result>; 
 <;result name="madhuri" type="tiles">;madhuri<;/result>; 
 <;result name="alia" type="tiles">;alia<;/result>; 
 <;result name="addUser" type="tiles">;mainTemplate<;/result>; 
 <;/action>; 
 <;/package>; 
 <;/struts>; 
</pre>
<p><b>myapp.properties</b></p>
<pre class="highlight">user.name=User Name 
user.age=User Age 
user.gender=Gender 
user.job=Job Type 
user.hobby=Hobbies 
submit=Add User 
</pre>
<p><b>Tiles Configuration file-</b><br />
<i><b>tiles-def.xml</b></i></p>
<pre class="highlight"><;?xml version="1.0" encoding="UTF-8" ?>; 
 
<;!DOCTYPE tiles-definitions PUBLIC 
 "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN" 
 "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">; 
 
<;tiles-definitions>; 
 
 <;definition name="mainTemplate" template="/mainTemplate.jsp">; 
 <;put-attribute name="title" value="User Registration Form"/>; 
 <;put-attribute name="header" value="/header.jsp"/>; 
 <;put-attribute name="menu" value="/menu.jsp"/>; 
 <;put-attribute name="body" value="/body.jsp"/>; 
 <;put-attribute name="footer" value="/footer.jsp"/>; 
 <;/definition>; 
 
 <;definition name="alia" extends="mainTemplate">; 
 <;put-attribute name="title" value="Alia Bhatt"/>; 
 <;put-attribute name="body" value="/alia.jsp"/>; 
 <;/definition>; 
 
 <;definition name="madhuri" extends="mainTemplate">; 
 <;put-attribute name="title" value="Madhuri Dixit"/>; 
 <;put-attribute name="body" value="/madhuri.jsp"/>; 
 <;/definition>; 
 
 <;definition name="success" extends="mainTemplate">; 
 <;put-attribute name="title" value="User Added Successfully"/>; 
 <;put-attribute name="body" value="/success.jsp"/>; 
 <;/definition>; 
 
<;/tiles-definitions>; 
</pre>
<p><b>create deployment descriptor</b><br />
<i><b>web.xml</b></i></p>
<pre class="highlight"><;?xml version="1.0" encoding="UTF-8"?>; 
<;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">; 
 <;display-name>;Struts2Hibernate3Spring3Tile2Integration<;/display-name>; 
 <;welcome-file-list>; 
 <;welcome-file>;users.jsp<;/welcome-file>; 
 <;/welcome-file-list>; 
 <;context-param>; 
 <;param-name>; 
 org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG 
 <;/param-name>; 
 <;param-value>; 
 /WEB-INF/tiles-def.xml 
 <;/param-value>; 
 <;/context-param>; 
 <;listener>; 
 <;listener-class>; 
 org.springframework.web.context.ContextLoaderListener 
 <;/listener-class>; 
 <;/listener>; 
 <;listener>; 
 <;listener-class>; 
 org.apache.struts2.tiles.StrutsTilesListener 
 <;/listener-class>; 
 <;/listener>; 
 <;filter>; 
 <;filter-name>;struts2<;/filter-name>; 
 <;filter-class>; 
 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter 
 <;/filter-class>; 
 <;/filter>; 
 <;filter-mapping>; 
 <;filter-name>;struts2<;/filter-name>; 
 <;url-pattern>;/*<;/url-pattern>; 
 <;/filter-mapping>; 
<;/web-app>; 
</pre>
<p>Now right click on the project name and click <b>Export >; WAR</b> File to create a War file. Then deploy this WAR in the Tomcat&#8217;s webapps directory. Finally, start Tomcat server and try to access</p>
<p><b>URL <i>http://localhost:8080/doj/user</i> </b></p>
<p>This will give you following screen:</p>
<div class="separator" style="clear: both; text-align: center;"><img src="http://dineshonjava.com/wp-content/uploads/2013/08/88888.png" border="0" /></div>
<p> ;</p>
</div>
<p>Fill data of user form and submit let see following screen we will get.</p>
<p><i><b>http://localhost:8080/doj/addUsermenu.action</b></i></p>
<div class="separator" style="clear: both; text-align: center;"><img src="http://dineshonjava.com/wp-content/uploads/2013/08/10101.png" border="0" /></div>
<p> ;</p>
</div>
<p><i><b>http://localhost:8080/doj/madhurimenu.action</b></i></p>
<div class="separator" style="clear: both; text-align: center;"><img src="http://dineshonjava.com/wp-content/uploads/2013/08/1212.png" border="0" /></div>
<p> ;</p>
</div>
</div>
<p><b>Download Source Code + Libs</b><br />
<b><a href="https://sites.google.com/a/dineshonjava.com/dineshonjava/dineshonjava/Struts2Hibernate3Spring3Tile2Integration.zip?attredirects=0&;d=1" target="_blank" rel="noopener">Struts2Hibernate3Spring3Tile2Integration.zip</a></b></p>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/struts2-integration-with-tiles2-spring3/">Previous</a> <;<; || <a href="https://dineshonjava.com/struts-2-baby-step-to-learn/">Index </a>|| >;>;<a href="https://dineshonjava.com/struts-2-and-json-example/">Next</a> >;>;</b></div>
<p> ;</p>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/struts2-integration-with-tiles2-spring3/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/struts-2-and-json-example/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '353'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…