Spring MVC Tiles Plugin with Example

2017.01.15 14:19

졸리운_곰 조회 수:1384

 

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.
Popular Spring Tutorials
  1. Spring Tutorial
  2. Spring MVC Web Tutorial
  3. Spring Boot Tutorial
  4. Spring JDBC Tutorial
  5. Spring AOP Tutorial
  6. Spring Security Tutorial
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

 
Spring 3 MVC Tiles Plugin with Example

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.
tile structure
Application Structure:
spring3-hibernate-application-architecture-with+tiles

EmployeeBean.java
  1. package com.dineshonjava.bean;  
  2.   
  3. /** 
  4.  * @author Dinesh Rajput 
  5.  * 
  6.  */  
  7. public class EmployeeBean {  
  8.  private Integer id;  
  9.  private String name;  
  10.  private Integer age;  
  11.  private Long salary;  
  12.  private String address;  
  13.    
  14.  public Long getSalary() {  
  15.   return salary;  
  16.  }  
  17.  public void setSalary(Long salary) {  
  18.   this.salary = salary;  
  19.  }  
  20.  public Integer getId() {  
  21.   return id;  
  22.  }  
  23.  public void setId(Integer id) {  
  24.   this.id = id;  
  25.  }  
  26.  public String getName() {  
  27.   return name;  
  28.  }  
  29.  public void setName(String name) {  
  30.   this.name = name;  
  31.  }  
  32.  public Integer getAge() {  
  33.   return age;  
  34.  }  
  35.  public void setAge(Integer age) {  
  36.   this.age = age;  
  37.  }  
  38.  public String getAddress() {  
  39.   return address;  
  40.  }  
  41.  public void setAddress(String address) {  
  42.   this.address = address;  
  43.  }  
  44. }  
Employee.java
  1. package com.dineshonjava.model;  
  2.   
  3. import java.io.Serializable;  
  4.   
  5. import javax.persistence.Column;  
  6. import javax.persistence.Entity;  
  7. import javax.persistence.GeneratedValue;  
  8. import javax.persistence.GenerationType;  
  9. import javax.persistence.Id;  
  10. import javax.persistence.Table;  
  11.   
  12. /** 
  13.  * @author Dinesh Rajput 
  14.  * 
  15.  */  
  16. @Entity  
  17. @Table(name="Employee")  
  18. public class Employee implements Serializable{  
  19.   
  20.  private static final long serialVersionUID = -723583058586873479L;  
  21.    
  22.  @Id  
  23.  @GeneratedValue(strategy=GenerationType.AUTO)  
  24.  @Column(name = "empid")  
  25.  private Integer empId;  
  26.    
  27.  @Column(name="empname")  
  28.  private String empName;  
  29.    
  30.  @Column(name="empaddress")  
  31.  private String empAddress;  
  32.    
  33.  @Column(name="salary")  
  34.  private Long salary;  
  35.    
  36.  @Column(name="empAge")  
  37.  private Integer empAge;  
  38.   
  39.  public Integer getEmpId() {  
  40.   return empId;  
  41.  }  
  42.   
  43.  public void setEmpId(Integer empId) {  
  44.   this.empId = empId;  
  45.  }  
  46.   
  47.  public String getEmpName() {  
  48.   return empName;  
  49.  }  
  50.   
  51.  public void setEmpName(String empName) {  
  52.   this.empName = empName;  
  53.  }  
  54.   
  55.  public String getEmpAddress() {  
  56.   return empAddress;  
  57.  }  
  58.   
  59.  public void setEmpAddress(String empAddress) {  
  60.   this.empAddress = empAddress;  
  61.  }  
  62.   
  63.  public Long getSalary() {  
  64.   return salary;  
  65.  }  
  66.   
  67.  public void setSalary(Long salary) {  
  68.   this.salary = salary;  
  69.  }  
  70.   
  71.  public Integer getEmpAge() {  
  72.   return empAge;  
  73.  }  
  74.   
  75.  public void setEmpAge(Integer empAge) {  
  76.   this.empAge = empAge;  
  77.  }  
  78. }  
EmployeeDao.java
  1. package com.dineshonjava.dao;  
  2.   
  3. import java.util.List;  
  4.   
  5. import com.dineshonjava.model.Employee;  
  6.   
  7. /** 
  8.  * @author Dinesh Rajput 
  9.  * 
  10.  */  
  11. public interface EmployeeDao {  
  12.    
  13.  public void addEmployee(Employee employee);  
  14.   
  15.  public List<Employee> listEmployeess();  
  16.    
  17.  public Employee getEmployee(int empid);  
  18.    
  19.  public void deleteEmployee(Employee employee);  
  20. }  
EmployeeDaoImpl.java
  1. package com.dineshonjava.dao;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.hibernate.SessionFactory;  
  6. import org.springframework.beans.factory.annotation.Autowired;  
  7. import org.springframework.stereotype.Repository;  
  8.   
  9. import com.dineshonjava.model.Employee;  
  10.   
  11. /** 
  12.  * @author Dinesh Rajput 
  13.  * 
  14.  */  
  15. @Repository("employeeDao")  
  16. public class EmployeeDaoImpl implements EmployeeDao {  
  17.   
  18.  @Autowired  
  19.  private SessionFactory sessionFactory;  
  20.    
  21.  public void addEmployee(Employee employee) {  
  22.    sessionFactory.getCurrentSession().saveOrUpdate(employee);  
  23.  }  
  24.   
  25.  @SuppressWarnings("unchecked")  
  26.  public List<Employee> listEmployeess() {  
  27.   return (List<Employee>) sessionFactory.getCurrentSession().createCriteria(Employee.class).list();  
  28.  }  
  29.   
  30.  public Employee getEmployee(int empid) {  
  31.   return (Employee) sessionFactory.getCurrentSession().get(Employee.class, empid);  
  32.  }  
  33.   
  34.  public void deleteEmployee(Employee employee) {  
  35.   sessionFactory.getCurrentSession().createQuery("DELETE FROM Employee WHERE empid = "+employee.getEmpId()).executeUpdate();  
  36.  }  
  37. }<span style="color: #4c1130;"><b>  
  38. </b></span>  
EmployeeService.java
  1. package com.dineshonjava.service;  
  2.   
  3. import java.util.List;  
  4.   
  5. import com.dineshonjava.model.Employee;  
  6.   
  7. /** 
  8.  * @author Dinesh Rajput 
  9.  * 
  10.  */  
  11. public interface EmployeeService {  
  12.    
  13.  public void addEmployee(Employee employee);  
  14.   
  15.  public List<Employee> listEmployeess();  
  16.    
  17.  public Employee getEmployee(int empid);  
  18.    
  19.  public void deleteEmployee(Employee employee);  
  20. }  
EmployeeServiceImpl.java
  1. package com.dineshonjava.service;  
  2.   
  3. import java.util.List;  
  4.   
  5. import org.springframework.beans.factory.annotation.Autowired;  
  6. import org.springframework.stereotype.Service;  
  7. import org.springframework.transaction.annotation.Propagation;  
  8. import org.springframework.transaction.annotation.Transactional;  
  9.   
  10. import com.dineshonjava.dao.EmployeeDao;  
  11. import com.dineshonjava.model.Employee;  
  12.   
  13. /** 
  14.  * @author Dinesh Rajput 
  15.  * 
  16.  */  
  17. @Service("employeeService")  
  18. @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)  
  19. public class EmployeeServiceImpl implements EmployeeService {  
  20.   
  21.  @Autowired  
  22.  private EmployeeDao employeeDao;  
  23.    
  24.  @Transactional(propagation = Propagation.REQUIRED, readOnly = false)  
  25.  public void addEmployee(Employee employee) {  
  26.   employeeDao.addEmployee(employee);  
  27.  }  
  28.    
  29.  public List<Employee> listEmployeess() {  
  30.   return employeeDao.listEmployeess();  
  31.  }  
  32.   
  33.  public Employee getEmployee(int empid) {  
  34.   return employeeDao.getEmployee(empid);  
  35.  }  
  36.    
  37.  public void deleteEmployee(Employee employee) {  
  38.   employeeDao.deleteEmployee(employee);  
  39.  }  
  40.   
  41. }  
EmployeeController.java
  1. package com.dineshonjava.controller;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.HashMap;  
  5. import java.util.List;  
  6. import java.util.Map;  
  7.   
  8. import org.springframework.beans.factory.annotation.Autowired;  
  9. import org.springframework.stereotype.Controller;  
  10. import org.springframework.validation.BindingResult;  
  11. import org.springframework.web.bind.annotation.ModelAttribute;  
  12. import org.springframework.web.bind.annotation.RequestMapping;  
  13. import org.springframework.web.bind.annotation.RequestMethod;  
  14. import org.springframework.web.servlet.ModelAndView;  
  15.   
  16. import com.dineshonjava.bean.EmployeeBean;  
  17. import com.dineshonjava.model.Employee;  
  18. import com.dineshonjava.service.EmployeeService;  
  19.   
  20. /** 
  21.  * @author Dinesh Rajput 
  22.  * 
  23.  */  
  24. @Controller  
  25. public class EmployeeController {  
  26.    
  27.  @Autowired  
  28.  private EmployeeService employeeService;  
  29.    
  30. @RequestMapping(value = "/save", method = RequestMethod.POST)  
  31. public ModelAndView saveEmployee(@ModelAttribute("command")EmployeeBean employeeBean,   
  32.    BindingResult result) {  
  33.   Employee employee = prepareModel(employeeBean);  
  34.   employeeService.addEmployee(employee);  
  35.   return new ModelAndView("redirect:/add.html");  
  36.  }  
  37.   
  38.  @RequestMapping(value="/employees", method = RequestMethod.GET)  
  39.  public ModelAndView listEmployees() {  
  40.   Map<String, Object> model = new HashMap<String, Object>();  
  41.   model.put("employees",  prepareListofBean(employeeService.listEmployeess()));  
  42.   return new ModelAndView("employeesList", model);  
  43.  }  
  44.   
  45.  @RequestMapping(value = "/add", method = RequestMethod.GET)  
  46.  public ModelAndView addEmployee(@ModelAttribute("command")EmployeeBean employeeBean,  
  47.    BindingResult result) {  
  48.   Map<String, Object> model = new HashMap<String, Object>();  
  49.   model.put("employees",  prepareListofBean(employeeService.listEmployeess()));  
  50.   return new ModelAndView("addEmployee", model);  
  51.  }  
  52.    
  53. @RequestMapping(value = "/index", method = RequestMethod.GET)  
  54. public ModelAndView welcome() {  
  55.   return new ModelAndView("redirect:/add.html");  
  56.  }  
  57.   
  58. @RequestMapping(value = "/delete", method = RequestMethod.GET)  
  59. public ModelAndView editEmployee(@ModelAttribute("command")EmployeeBean employeeBean,  
  60.    BindingResult result) {  
  61.   employeeService.deleteEmployee(prepareModel(employeeBean));  
  62.   Map<String, Object> model = new HashMap<String, Object>();  
  63.   model.put("employee"null);  
  64.   model.put("employees",  prepareListofBean(employeeService.listEmployeess()));  
  65.   return new ModelAndView("addEmployee", model);  
  66.  }  
  67.    
  68. @RequestMapping(value = "/edit", method = RequestMethod.GET)  
  69. public ModelAndView deleteEmployee(@ModelAttribute("command")EmployeeBean employeeBean,  
  70.    BindingResult result) {  
  71.   Map<String, Object> model = new HashMap<String, Object>();  
  72.   model.put("employee", prepareEmployeeBean(employeeService.getEmployee(employeeBean.getId())));  
  73.   model.put("employees",  prepareListofBean(employeeService.listEmployeess()));  
  74.   return new ModelAndView("addEmployee", model);  
  75.  }  
  76.    
  77.  private Employee prepareModel(EmployeeBean employeeBean){  
  78.   Employee employee = new Employee();  
  79.   employee.setEmpAddress(employeeBean.getAddress());  
  80.   employee.setEmpAge(employeeBean.getAge());  
  81.   employee.setEmpName(employeeBean.getName());  
  82.   employee.setSalary(employeeBean.getSalary());  
  83.   employee.setEmpId(employeeBean.getId());  
  84.   employeeBean.setId(null);  
  85.   return employee;  
  86.  }  
  87.    
  88.  private List<EmployeeBean> prepareListofBean(List<Employee> employees){  
  89.   List<employeebean> beans = null;  
  90.   if(employees != null && !employees.isEmpty()){  
  91.    beans = new ArrayList<EmployeeBean>();  
  92.    EmployeeBean bean = null;  
  93.    for(Employee employee : employees){  
  94.     bean = new EmployeeBean();  
  95.     bean.setName(employee.getEmpName());  
  96.     bean.setId(employee.getEmpId());  
  97.     bean.setAddress(employee.getEmpAddress());  
  98.     bean.setSalary(employee.getSalary());  
  99.     bean.setAge(employee.getEmpAge());  
  100.     beans.add(bean);  
  101.    }  
  102.   }  
  103.   return beans;  
  104.  }  
  105.    
  106.  private EmployeeBean prepareEmployeeBean(Employee employee){  
  107.   EmployeeBean bean = new EmployeeBean();  
  108.   bean.setAddress(employee.getEmpAddress());  
  109.   bean.setAge(employee.getEmpAge());  
  110.   bean.setName(employee.getEmpName());  
  111.   bean.setSalary(employee.getSalary());  
  112.   bean.setId(employee.getEmpId());  
  113.   return bean;  
  114.  }  
  115. }  
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.   
  6. <html>  
  7.  <head>  
  8.     
  9.   <title>Spring MVC Form Handling</title>  
  10.  </head>  
  11.  <body>  
  12.   <h2>Add Employee Data</h2>  
  13. <form:form action="/sdnext/save.html" method="POST">       
  14.   <table>
  15.    <tbody>  
  16.       <tr>          
  17.         <td><form:label path="id">Employee ID:</form:label></td>
  18.           <td><form:input path="id" readonly="true" value="${employee.id}"> 
  19.           </form:input></td>
  20.       </tr>  
  21.       <tr>  
  22.          <td><form:label path="name">Employee Name:</form:label></td> 
  23.         <td><form:input path="name" value="${employee.name}">   
  24.          </form:input></td> 
  25.      </tr>  
  26.      <tr>
  27.        <td><form:label path="age">Employee Age:</form:label></td> 
  28.        <td><form:input path="age" value="${employee.age}">
  29.        </form:input></td> 
  30.      </tr>  
  31.      <tr> 
  32.         <td><form:label path="salary">Employee Salary:</form:label></td> 
  33.         <td><form:input path="salary" value="${employee.salary}">
  34.          </form:input></td>
  35.      </tr>  
  36.      <tr> 
  37.         <td><form:label path="address">Employee Address:</form:label></td> 
  38.         <td><form:input path="address" value="${employee.address}">
  39.          </form:input></td> 
  40.      </tr>  
  41.     <tr> 
  42.         <td colspan="2"> 
  43.           <input type="submit" value="Submit"></td> 
  44.      </tr>  
  45.    </tbody> 
  46.   </table>  
  47. </form:form>    
  48.   <c:if test="${!empty employees}">  
  49.    <h2>  List Employees</h2>  
  50.  <table align="left" border="1"> 
  51.    <tbody> 
  52.      <tr> 
  53.         <th>Employee ID</th> 
  54.         <th>Employee Name</th> 
  55.         <th>Employee Age</th>
  56.         <th>Employee Salary</th> 
  57.         <th>Employee Address</th> 
  58.         <th>Actions on Row</th> 
  59.    </tr>  
  60. <c:foreach items="${employees}" var="employee">
  61.  <tr> 
  62.     <td><c:out value="${employee.id}"></c:out> 
  63. </td>
  64.       <td><c:out value="${employee.name}"></c:out>
  65.  </td> 
  66.      <td><c:out value="${employee.age}"></c:out>
  67.  </td>
  68.       <td><c:out value="${employee.salary}"></c:out> 
  69. </td> 
  70.      <td><c:out value="${employee.address}"></c:out>
  71.  </td>
  72.       <td align="center"><a href="edit.html/?id=${employee.id}">Edit</a> |  
  73.      <a href="delete.html/?id=${employee.id}">Delete</a> 
  74.    </td> 
  75.    </tr> 
  76. </c:foreach>
  77.  
  78. </tbody></table>  
  79. </c:if>  
  80.  </body>  
  81. </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.   
  5. <html>  
  6. <head>  
  7. <title>All Employees</title>  
  8. </head>  
  9. <body>  
  10. <h1>  
  11. List Employees</h1>  
  12. <h3>  
  13. <a href="http://add.html/">Add More Employee</a></h3>  
  14. <c:if test="${!empty employees}">  
  15.  
  16. <table align="left" border="1"> 
  17. <tbody>  
  18. <tr> 
  19.     <th>Employee ID</th> 
  20.     <th>Employee Name</th> 
  21.     <th>Employee Age</th> 
  22.     <th>Employee Salary</th> 
  23.     <th>Employee Address</th>
  24.     </tr>  
  25. <c:foreach items="${employees}" var="employee"> 
  26. <tr> 
  27.      <td><c:out value="${employee.id}"></c:out>
  28.  </td> 
  29.      <td><c:out value="${employee.name}"></c:out> 
  30. </td> 
  31.      <td><c:out value="${employee.age}"></c:out> 
  32. </td>
  33.       <td><c:out value="${employee.salary}"></c:out> 
  34. </td> 
  35.      <td><c:out value="${employee.address}"></c:out></td> 
  36.   </tr>  
  37. </c:foreach>
  38. </tbody>
  39.  </table>  
  40. </c:if>  
  41. </body>  
  42. </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.  
  2.     <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.   
  4. <html>  
  5.   <head>  
  6.       
  7.     <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>
  8. </body>  
  9. </html>

tilesapp
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:
 
tileoutput

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.
 
tileoutput2


Dwonload this Application SourceCode+Libs

Spring3TilesApp.zip

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

[출처] http://www.dineshonjava.com/2012/12/spring-3-mvc-tiles-plugin-with-example.html

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
26 [bootstrap] spring 프로젝트에 bootstrap 적용 file 졸리운_곰 2017.01.29 164
25 eGov 표준프레임워크(전자정부프레임워크) 공통 컴포넌트 사용법 : Common Component file 졸리운_곰 2017.01.29 1030
24 Passing Javascript object and object list to Spring controller 졸리운_곰 2017.01.23 92
23 뷰에 모델(Model) 전달 file 졸리운_곰 2017.01.22 128
22 CentOS에서 Apache Tomcat 설치하기 졸리운_곰 2017.01.18 490
» Spring MVC Tiles Plugin with Example file 졸리운_곰 2017.01.15 1384
20 Spring MVC Tiles 3 Integration Tutorial file 졸리운_곰 2017.01.15 173
19 Spring 3 MVC: Tiles Plugin Tutorial with Example in Eclipse file 졸리운_곰 2017.01.15 194
18 MyBatis 에서 한 insert 태그로 여러 Insert문 수행 졸리운_곰 2016.12.09 112
17 Web App Architecture - the Spring MVC - AngularJs stack file 졸리운_곰 2016.11.20 208
16 Introduction to Angular 2 with Spring MVC file 졸리운_곰 2016.11.20 676
15 Migrating a Spring Web MVC application from JSP to AngularJS file 졸리운_곰 2016.11.20 114
14 스프링(Spring) MVC 프레임워크(Model View Controller Framework) file 졸리운_곰 2016.11.16 151
13 JSP 정리 졸리운_곰 2016.09.11 332
12 JSP 요약 정리 file 졸리운_곰 2016.09.11 1294
11 전자정부 eGov 프레임워크 모바일 실행환경 Upgrade 가이드 file 졸리운_곰 2016.08.02 327
10 전자정부 eGov 프레임워크 개발프레임워크 개발환경 졸리운_곰 2016.08.02 474
9 표준프레임워크 실행환경 3.5 졸리운_곰 2016.08.02 172
8 전자정부 표준프레임워크 3.5 기반 개발 시작하기(Getting Started) file 졸리운_곰 2016.08.02 291
7 스프링(Spring) MVC 프레임워크(Model View Controller Framework) file 졸리운_곰 2016.07.31 103
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED