Spring Framework

Spring MVC Tiles Plugin with Example

In this tutorial we will discuss about the tiles and build a simple SpringMVC  application that utilizes templates using the Apache Tile 3 framework. Now we will create a template version of our pages, and compare it with non-template versions of the same pages. We will split the content, style, and template of these pages logically.

What is Apache Tiles 3.0.1?
Apache Tiles is a templating framework built to simplify the development of web application user interfaces.

Apache Tiles is a popular and mostly used templating framework for java based web application. Tiles became more popular because Struts 1.x uses Tiles as its default templating framework. Spring3MVC which is an MVC framework, like Struts, also supports integration of Tiles as its templating framework.

Tiles allows developer to define page fragments(or parts) which can be assembled into a complete page at run-time. These fragments, or tiles, can be used as simple includes in order to reduce the duplication of common page elements or embedded within other tiles to develop a series of reusable templates. These templates streamline the development of a consistent look and feel across an entire application.

Let us see how we can integrate Spring3MVC and Tiles.
You can download Tiles binaries from here

Application Layout

 


A web portal have many reusable templates like header, footer, menu etc. These elements remains same in every web page to give a uniform feel and look to improve presentation of portal. But difficult part is when you need to alter these common items.

The Tiles framework solve this problem by using templatization mechanism. We create a common Header, Footer, Menu page and include this in each page. A common layout of website is defined in a central configuration file and this layout can be extended across all the web pages of the web application.

 

Add the following required tiles jars to WEB-INF/lib folder.

  • tiles-api-2.2.2.jar
  • tiles-core-2.2.2.jar
  • tiles-jsp-2.2.2.jar
  • tiles-servlet-2.2.2.jar
  • tiles-template-2.2.2.jar

In the previous chapter we run an application of CRUD operation on the Employee table using Spring3MVC and Hibernate3. Now same we will build same application using tiles configuration (or Tiles View Resolver) as view in stead of JstlView (or JSP View resolver).
Updated view of our application with using the tiles configuration look like as below diagram.

Application Structure:

EmployeeBean.java

  1. package com.dineshonjava.bean;
  2. /**
  3.  * @author Dinesh Rajput
  4.  *
  5.  */
  6. public class EmployeeBean {
  7.  private Integer id;
  8.  private String name;
  9.  private Integer age;
  10.  private Long salary;
  11.  private String address;
  12.  public Long getSalary() {
  13.   return salary;
  14.  }
  15.  public void setSalary(Long salary) {
  16.   this.salary = salary;
  17.  }
  18.  public Integer getId() {
  19.   return id;
  20.  }
  21.  public void setId(Integer id) {
  22.   this.id = id;
  23.  }
  24.  public String getName() {
  25.   return name;
  26.  }
  27.  public void setName(String name) {
  28.   this.name = name;
  29.  }
  30.  public Integer getAge() {
  31.   return age;
  32.  }
  33.  public void setAge(Integer age) {
  34.   this.age = age;
  35.  }
  36.  public String getAddress() {
  37.   return address;
  38.  }
  39.  public void setAddress(String address) {
  40.   this.address = address;
  41.  }
  42. }

Employee.java

  1. package com.dineshonjava.model;
  2. import java.io.Serializable;
  3. import javax.persistence.Column;
  4. import javax.persistence.Entity;
  5. import javax.persistence.GeneratedValue;
  6. import javax.persistence.GenerationType;
  7. import javax.persistence.Id;
  8. import javax.persistence.Table;
  9. /**
  10.  * @author Dinesh Rajput
  11.  *
  12.  */
  13. @Entity
  14. @Table(name=”Employee”)
  15. public class Employee implements Serializable{
  16.  private static final long serialVersionUID = -723583058586873479L;
  17.  @Id
  18.  @GeneratedValue(strategy=GenerationType.AUTO)
  19.  @Column(name = “empid”)
  20.  private Integer empId;
  21.  @Column(name=”empname”)
  22.  private String empName;
  23.  @Column(name=”empaddress”)
  24.  private String empAddress;
  25.  @Column(name=”salary”)
  26.  private Long salary;
  27.  @Column(name=”empAge”)
  28.  private Integer empAge;
  29.  public Integer getEmpId() {
  30.   return empId;
  31.  }
  32.  public void setEmpId(Integer empId) {
  33.   this.empId = empId;
  34.  }
  35.  public String getEmpName() {
  36.   return empName;
  37.  }
  38.  public void setEmpName(String empName) {
  39.   this.empName = empName;
  40.  }
  41.  public String getEmpAddress() {
  42.   return empAddress;
  43.  }
  44.  public void setEmpAddress(String empAddress) {
  45.   this.empAddress = empAddress;
  46.  }
  47.  public Long getSalary() {
  48.   return salary;
  49.  }
  50.  public void setSalary(Long salary) {
  51.   this.salary = salary;
  52.  }
  53.  public Integer getEmpAge() {
  54.   return empAge;
  55.  }
  56.  public void setEmpAge(Integer empAge) {
  57.   this.empAge = empAge;
  58.  }
  59. }

EmployeeDao.java

  1. package com.dineshonjava.dao;
  2. import java.util.List;
  3. import com.dineshonjava.model.Employee;
  4. /**
  5.  * @author Dinesh Rajput
  6.  *
  7.  */
  8. public interface EmployeeDao {
  9.  public void addEmployee(Employee employee);
  10.  public List<Employee> listEmployeess();
  11.  public Employee getEmployee(int empid);
  12.  public void deleteEmployee(Employee employee);
  13. }

EmployeeDaoImpl.java

  1. package com.dineshonjava.dao;
  2. import java.util.List;
  3. import org.hibernate.SessionFactory;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.stereotype.Repository;
  6. import com.dineshonjava.model.Employee;
  7. /**
  8.  * @author Dinesh Rajput
  9.  *
  10.  */
  11. @Repository(“employeeDao”)
  12. public class EmployeeDaoImpl implements EmployeeDao {
  13.  @Autowired
  14.  private SessionFactory sessionFactory;
  15.  public void addEmployee(Employee employee) {
  16.    sessionFactory.getCurrentSession().saveOrUpdate(employee);
  17.  }
  18.  @SuppressWarnings(“unchecked”)
  19.  public List<Employee> listEmployeess() {
  20.   return (List<Employee>) sessionFactory.getCurrentSession().createCriteria(Employee.class).list();
  21.  }
  22.  public Employee getEmployee(int empid) {
  23.   return (Employee) sessionFactory.getCurrentSession().get(Employee.class, empid);
  24.  }
  25.  public void deleteEmployee(Employee employee) {
  26.   sessionFactory.getCurrentSession().createQuery(“DELETE FROM Employee WHERE empid = “+employee.getEmpId()).executeUpdate();
  27.  }
  28. }<span style=”color: #4c1130;”><b>
  29. </b></span>

EmployeeService.java

  1. package com.dineshonjava.service;
  2. import java.util.List;
  3. import com.dineshonjava.model.Employee;
  4. /**
  5.  * @author Dinesh Rajput
  6.  *
  7.  */
  8. public interface EmployeeService {
  9.  public void addEmployee(Employee employee);
  10.  public List<Employee> listEmployeess();
  11.  public Employee getEmployee(int empid);
  12.  public void deleteEmployee(Employee employee);
  13. }

EmployeeServiceImpl.java

  1. package com.dineshonjava.service;
  2. import java.util.List;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Service;
  5. import org.springframework.transaction.annotation.Propagation;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import com.dineshonjava.dao.EmployeeDao;
  8. import com.dineshonjava.model.Employee;
  9. /**
  10.  * @author Dinesh Rajput
  11.  *
  12.  */
  13. @Service(“employeeService”)
  14. @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
  15. public class EmployeeServiceImpl implements EmployeeService {
  16.  @Autowired
  17.  private EmployeeDao employeeDao;
  18.  @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
  19.  public void addEmployee(Employee employee) {
  20.   employeeDao.addEmployee(employee);
  21.  }
  22.  public List<Employee> listEmployeess() {
  23.   return employeeDao.listEmployeess();
  24.  }
  25.  public Employee getEmployee(int empid) {
  26.   return employeeDao.getEmployee(empid);
  27.  }
  28.  public void deleteEmployee(Employee employee) {
  29.   employeeDao.deleteEmployee(employee);
  30.  }
  31. }

EmployeeController.java

  1. package com.dineshonjava.controller;
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.List;
  5. import java.util.Map;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.stereotype.Controller;
  8. import org.springframework.validation.BindingResult;
  9. import org.springframework.web.bind.annotation.ModelAttribute;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RequestMethod;
  12. import org.springframework.web.servlet.ModelAndView;
  13. import com.dineshonjava.bean.EmployeeBean;
  14. import com.dineshonjava.model.Employee;
  15. import com.dineshonjava.service.EmployeeService;
  16. /**
  17.  * @author Dinesh Rajput
  18.  *
  19.  */
  20. @Controller
  21. public class EmployeeController {
  22.  @Autowired
  23.  private EmployeeService employeeService;
  24. @RequestMapping(value = “/save”, method = RequestMethod.POST)
  25. public ModelAndView saveEmployee(@ModelAttribute(“command”)EmployeeBean employeeBean,
  26.    BindingResult result) {
  27.   Employee employee = prepareModel(employeeBean);
  28.   employeeService.addEmployee(employee);
  29.   return new ModelAndView(“redirect:/add.html”);
  30.  }
  31.  @RequestMapping(value=”/employees”, method = RequestMethod.GET)
  32.  public ModelAndView listEmployees() {
  33.   Map<String, Object> model = new HashMap<String, Object>();
  34.   model.put(“employees”,  prepareListofBean(employeeService.listEmployeess()));
  35.   return new ModelAndView(“employeesList”, model);
  36.  }
  37.  @RequestMapping(value = “/add”, method = RequestMethod.GET)
  38.  public ModelAndView addEmployee(@ModelAttribute(“command”)EmployeeBean employeeBean,
  39.    BindingResult result) {
  40.   Map<String, Object> model = new HashMap<String, Object>();
  41.   model.put(“employees”,  prepareListofBean(employeeService.listEmployeess()));
  42.   return new ModelAndView(“addEmployee”, model);
  43.  }
  44. @RequestMapping(value = “/index”, method = RequestMethod.GET)
  45. public ModelAndView welcome() {
  46.   return new ModelAndView(“redirect:/add.html”);
  47.  }
  48. @RequestMapping(value = “/delete”, method = RequestMethod.GET)
  49. public ModelAndView editEmployee(@ModelAttribute(“command”)EmployeeBean employeeBean,
  50.    BindingResult result) {
  51.   employeeService.deleteEmployee(prepareModel(employeeBean));
  52.   Map<String, Object> model = new HashMap<String, Object>();
  53.   model.put(“employee”, null);
  54.   model.put(“employees”,  prepareListofBean(employeeService.listEmployeess()));
  55.   return new ModelAndView(“addEmployee”, model);
  56.  }
  57. @RequestMapping(value = “/edit”, method = RequestMethod.GET)
  58. public ModelAndView deleteEmployee(@ModelAttribute(“command”)EmployeeBean employeeBean,
  59.    BindingResult result) {
  60.   Map<String, Object> model = new HashMap<String, Object>();
  61.   model.put(“employee”, prepareEmployeeBean(employeeService.getEmployee(employeeBean.getId())));
  62.   model.put(“employees”,  prepareListofBean(employeeService.listEmployeess()));
  63.   return new ModelAndView(“addEmployee”, model);
  64.  }
  65.  private Employee prepareModel(EmployeeBean employeeBean){
  66.   Employee employee = new Employee();
  67.   employee.setEmpAddress(employeeBean.getAddress());
  68.   employee.setEmpAge(employeeBean.getAge());
  69.   employee.setEmpName(employeeBean.getName());
  70.   employee.setSalary(employeeBean.getSalary());
  71.   employee.setEmpId(employeeBean.getId());
  72.   employeeBean.setId(null);
  73.   return employee;
  74.  }
  75.  private List<EmployeeBean> prepareListofBean(List<Employee> employees){
  76.   List<employeebean> beans = null;
  77.   if(employees != null && !employees.isEmpty()){
  78.    beans = new ArrayList<EmployeeBean>();
  79.    EmployeeBean bean = null;
  80.    for(Employee employee : employees){
  81.     bean = new EmployeeBean();
  82.     bean.setName(employee.getEmpName());
  83.     bean.setId(employee.getEmpId());
  84.     bean.setAddress(employee.getEmpAddress());
  85.     bean.setSalary(employee.getSalary());
  86.     bean.setAge(employee.getEmpAge());
  87.     beans.add(bean);
  88.    }
  89.   }
  90.   return beans;
  91.  }
  92.  private EmployeeBean prepareEmployeeBean(Employee employee){
  93.   EmployeeBean bean = new EmployeeBean();
  94.   bean.setAddress(employee.getEmpAddress());
  95.   bean.setAge(employee.getEmpAge());
  96.   bean.setName(employee.getEmpName());
  97.   bean.setSalary(employee.getSalary());
  98.   bean.setId(employee.getEmpId());
  99.   return bean;
  100.  }
  101. }

Spring Web configuration file web.xml

<web-app version="2.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemalocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

   <servlet>
     <servlet-name>sdnext</servlet-name>
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     <init-param>
            <param-name>contextConfigLocation</param-name><param-value>/WEB-INF/config/sdnext-servlet.xml</param-value></init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>

 <servlet-mapping>
  <servlet-name>sdnext</servlet-name>
  <url-pattern>*.html</url-pattern>
 </servlet-mapping>

 <welcome-file-list>
  <welcome-file>index.html</welcome-file>
 </welcome-file-list>

</web-app>


Spring Web configuration file sdnext-servlet.xml

<beans xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" 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:property-placeholder location="classpath:resources/database.properties">
</context:property-placeholder>
<context:component-scan base-package="com.dineshonjava">
</context:component-scan>

<tx:annotation-driven transaction-manager="hibernateTransactionManager">
</tx:annotation-driven>

<!-- <bean id="jspViewResolver"
 class="org.springframework.web.servlet.view.InternalResourceViewResolver">
 <property name="viewClass"
  value="org.springframework.web.servlet.view.JstlView"></property>
 <property name="prefix" value="/WEB-INF/views/"></property>
 <property name="suffix" value=".jsp"></property>
</bean> -->
 
<bean class="org.springframework.web.servlet.view.UrlBasedViewResolver" id="viewResolver">
    <property name="viewClass">
 <value>
     org.springframework.web.servlet.view.tiles2.TilesView
 </value>
     </property>
</bean>
<bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer" id="tilesConfigurer">
    <property name="definitions">
  <list>
      <value>/WEB-INF/config/tiles.xml</value>
  </list>
      </property>
</bean>

<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.model.Employee</value>
  </list>
 </property>
 <property name="hibernateProperties">
 <props>
  <prop key="hibernate.dialect">${hibernate.dialect}</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>
</beans>

tiles.xml

<tiles-definitions>
    <definition name="base.definition" template="/WEB-INF/views/mainTemplate.jsp">
        <put-attribute name="title" value=""></put-attribute>
        <put-attribute name="header" value="/WEB-INF/views/header.jsp"></put-attribute>
        <put-attribute name="menu" value="/WEB-INF/views/menu.jsp"></put-attribute>
        <put-attribute name="body" value=""></put-attribute>
        <put-attribute name="footer" value="/WEB-INF/views/footer.jsp"></put-attribute>
    </definition>
 
    <definition extends="base.definition" name="addEmployee">
        <put-attribute name="title" value="Employee Data Form"></put-attribute>
        <put-attribute name="body" value="/WEB-INF/views/addEmployee.jsp"></put-attribute>
    </definition>
    
    <definition extends="base.definition" name="employeesList">
        <put-attribute name="title" value="Employees List"></put-attribute>
        <put-attribute name="body" value="/WEB-INF/views/employeesList.jsp"></put-attribute>
    </definition>
 
</tiles-definitions>

database.properties

database.driver=com.mysql.jdbc.Driver
database.url=jdbc:mysql://localhost:3306/DAVDB
database.user=root
database.password=root
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.hbm2ddl.auto=update

addEmployee.jsp

  1. <%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
  2.     pageEncoding=”ISO-8859-1″%>
  3. <%@taglib uri=”http://www.springframework.org/tags/form” prefix=”form”%>
  4. <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%>
  5. <html>
  6.  <head>
  7.   <title>Spring MVC Form Handling</title>
  8.  </head>
  9.  <body>
  10.   <h2>Add Employee Data</h2>
  11. <form:form action=”/sdnext/save.html” method=”POST”>
  12.   <table>
  13.    <tbody>
  14.       <tr>
  15.         <td><form:label path=”id”>Employee ID:</form:label></td>
  16.           <td><form:input path=”id” readonly=”true” value=”${employee.id}”>
  17.           </form:input></td>
  18.       </tr>
  19.       <tr>
  20.          <td><form:label path=”name”>Employee Name:</form:label></td>
  21.         <td><form:input path=”name” value=”${employee.name}”>
  22.          </form:input></td>
  23.      </tr>
  24.      <tr>
  25.        <td><form:label path=”age”>Employee Age:</form:label></td>
  26.        <td><form:input path=”age” value=”${employee.age}”>
  27.        </form:input></td>
  28.      </tr>
  29.      <tr>
  30.         <td><form:label path=”salary”>Employee Salary:</form:label></td>
  31.         <td><form:input path=”salary” value=”${employee.salary}”>
  32.          </form:input></td>
  33.      </tr>
  34.      <tr>
  35.         <td><form:label path=”address”>Employee Address:</form:label></td>
  36.         <td><form:input path=”address” value=”${employee.address}”>
  37.          </form:input></td>
  38.      </tr>
  39.     <tr>
  40.         <td colspan=”2″>
  41.           <input type=”submit” value=”Submit”></td>
  42.      </tr>
  43.    </tbody>
  44.   </table>
  45. </form:form>
  46.   <c:if test=”${!empty employees}”>
  47.    <h2>  List Employees</h2>
  48.  <table align=”left” border=”1″>
  49.    <tbody>
  50.      <tr>
  51.         <th>Employee ID</th>
  52.         <th>Employee Name</th>
  53.         <th>Employee Age</th>
  54.         <th>Employee Salary</th>
  55.         <th>Employee Address</th>
  56.         <th>Actions on Row</th>
  57.    </tr>
  58. <c:foreach items=”${employees}” var=”employee”>
  59.  <tr>
  60.     <td><c:out value=”${employee.id}”></c:out>
  61. </td>
  62.       <td><c:out value=”${employee.name}”></c:out>
  63.  </td>
  64.      <td><c:out value=”${employee.age}”></c:out>
  65.  </td>
  66.       <td><c:out value=”${employee.salary}”></c:out>
  67. </td>
  68.      <td><c:out value=”${employee.address}”></c:out>
  69.  </td>
  70.       <td align=”center”><a href=”edit.html/?id=${employee.id}”>Edit</a> |
  71.      <a href=”delete.html/?id=${employee.id}”>Delete</a>
  72.    </td>
  73.    </tr>
  74. </c:foreach>
  75. </tbody></table>
  76. </c:if>
  77.  </body>
  78. </html>

employeesList.jsp

  1. <%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
  2.     pageEncoding=”ISO-8859-1″%>
  3. <%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c”%>
  4. <html>
  5. <head>
  6. <title>All Employees</title>
  7. </head>
  8. <body>
  9. <h1>
  10. List Employees</h1>
  11. <h3>
  12. <a href=”http://add.html/”>Add More Employee</a></h3>
  13. <c:if test=”${!empty employees}”>
  14. <table align=”left” border=”1″>
  15. <tbody>
  16. <tr>
  17.     <th>Employee ID</th>
  18.     <th>Employee Name</th>
  19.     <th>Employee Age</th>
  20.     <th>Employee Salary</th>
  21.     <th>Employee Address</th>
  22.     </tr>
  23. <c:foreach items=”${employees}” var=”employee”>
  24. <tr>
  25.      <td><c:out value=”${employee.id}”></c:out>
  26.  </td>
  27.      <td><c:out value=”${employee.name}”></c:out>
  28. </td>
  29.      <td><c:out value=”${employee.age}”></c:out>
  30. </td>
  31.       <td><c:out value=”${employee.salary}”></c:out>
  32. </td>
  33.      <td><c:out value=”${employee.address}”></c:out></td>
  34.   </tr>
  35. </c:foreach>
  36. </tbody>
  37.  </table>
  38. </c:if>
  39. </body>
  40. </html>

menu.jsp

  1.   <h2>  Menu</h2>
  2. 1. <a href=”employees.html”>List of Employees</a>
  3. 2. <a href=”add.html”>Add Employee</a>

header.jsp

  1. <h2>Header- Employee Management System</h2>

footer.jsp

  1.     <p>Copyright &copy; 2013 dineshonjava.com</p>

mainTemplate.jsp

  1. <%@ page language=”java” contentType=”text/html; charset=ISO-8859-1″
  2.     pageEncoding=”ISO-8859-1″%>
  3. <html>
  4.   <head>
  5.     <title>
    <tiles:insertAttribute name=”title” ignore=”true”></tiles:insertAttribute>
    </title>
    </head>
    <body>
    <table border=”1″ cellpadding=”2″ cellspacing=”2″ align=”left”>
    <tr>
    <td colspan=”2″ align=”center”>
    <tiles:insertAttribute name=”header”></tiles:insertAttribute>
    </td>
    </tr>
    <tr>
    <td>
    <tiles:insertAttribute name=”menu”></tiles:insertAttribute>
    </td>
    <td>
    <tiles:insertAttribute name=”body”></tiles:insertAttribute>
    </td>
    </tr>
    <tr>
    <td colspan=”2″  align=”center”>
    <tiles:insertAttribute name=”footer”></tiles:insertAttribute>
    </td>
    </tr>
    </table>
  6. </body>
  7. </html>


Once you are done with creating source and configuration files, export your application. Right click on your application and use Export-> WAR File option and save your Spring3TilesApp.war file in Tomcat’s webapps folder.

Now start your Tomcat server and make sure you are able to access other web pages from webapps folder using a standard browser. Now try a URL http://localhost:8080/sdnext/ and you should see the following result if everything is fine with your Spring Web Application:

Now we click on the List of Employee link on the Menu section then we get the following output screen we observe that only body of the mainTemplate is refreshed.

Dwonload this Application SourceCode+Libs

Spring3TilesApp.zip

   <<Spring Web MVC Framework |index| Spring 3 MVC Framework with Interceptor>> 

Previous
Next
Dinesh Rajput

Dinesh Rajput is the chief editor of a website Dineshonjava, a technical blog dedicated to the Spring and Java technologies. It has a series of articles related to Java technologies. Dinesh has been a Spring enthusiast since 2008 and is a Pivotal Certified Spring Professional, an author of a book Spring 5 Design Pattern, and a blogger. He has more than 10 years of experience with different aspects of Spring and Java design and development. His core expertise lies in the latest version of Spring Framework, Spring Boot, Spring Security, creating REST APIs, Microservice Architecture, Reactive Pattern, Spring AOP, Design Patterns, Struts, Hibernate, Web Services, Spring Batch, Cassandra, MongoDB, and Web Application Design and Architecture. He is currently working as a technology manager at a leading product and web development company. He worked as a developer and tech lead at the Bennett, Coleman & Co. Ltd and was the first developer in his previous company, Paytm. Dinesh is passionate about the latest Java technologies and loves to write technical blogs related to it. He is a very active member of the Java and Spring community on different forums. When it comes to the Spring Framework and Java, Dinesh tops the list!

Share
Published by
Dinesh Rajput

Recent Posts

Strategy Design Patterns using Lambda

Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…

2 years ago

Decorator Pattern using Lambda

Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…

2 years ago

Delegating pattern using lambda

Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…

2 years ago

Spring Vs Django- Know The Difference Between The Two

Technology has emerged a lot in the last decade, and now we have artificial intelligence;…

2 years ago

TOP 20 MongoDB INTERVIEW QUESTIONS 2022

Managing a database is becoming increasingly complex now due to the vast amount of data…

2 years ago

Scheduler @Scheduled Annotation Spring Boot

Overview In this article, we will explore Spring Scheduler how we could use it by…

2 years ago