layout.jsp
======
<%@
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>
<title>
<tiles:insertAttribute
name="title" />
</title>
</head>
<body>
<table border="1"
cellpadding="2" cellspacing="2" align="center"
>
<tr>
<td height="30"
colspan="2" >
<tiles:insertAttribute
name="header" />
</td>
</tr>
<tr>
<td height="200"
><tiles:insertAttribute name="menu" /></td>
<td height="200"
><tiles:insertAttribute name="body" /></td>
</tr>
<tr>
<td height="30"
colspan="2" ><tiles:insertAttribute name="footer"
/> </td>
</tr>
</table>
</body>
</html>
tiles.xml
=====
<?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="base.definition"
template="/WEB-INF/jsp/layout.jsp">
<put-attribute
name="title" value="This is base application" />
<put-attribute
name="header" value="/WEB-INF/jsp/header.jsp" />
<put-attribute name="menu"
value="/WEB-INF/jsp/menu.jsp" />
<put-attribute name="body"
value="/WEB-INF/jsp/general.jsp" />
<put-attribute name="footer"
value="/WEB-INF/jsp/footer.jsp" />
</definition>
<definition
name="page1.definition" extends="base.definition">
<put-attribute
name="title" value="This is Page 1 application" />
<put-attribute name="body"
value="/WEB-INF/jsp/page1.jsp" />
<put-attribute
name="footer" value="/WEB-INF/jsp/footer.jsp" />
</definition>
<definition
name="page2.definition" extends="base.definition">
<put-attribute
name="title" value="This is Page 2 application" />
<put-attribute name="body"
value="/WEB-INF/jsp/page2.jsp" />
</definition>
</tiles-definitions>
dispatcher-servlet.xml
==============
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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">
<context:component-scan
base-package="myspring" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property
name="viewClass">
<value>
org.springframework.web.servlet.view.tiles2.TilesView
</value>
</property>
</bean>
<bean
id="tilesConfigurer"
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property
name="definitions">
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
</beans>
index.jsp
======
<a
href="base.htm">Please click here to navigate to Tiles
application</a>
MyController.java
===========
package
myspring;
import
org.springframework.stereotype.Controller;
import
org.springframework.ui.ModelMap;
import
org.springframework.web.bind.annotation.RequestMapping;
@Controller
public
class MyController {
@RequestMapping("base.htm")
public String Show(ModelMap map){
return "base.definition";
}
@RequestMapping("page1.htm")
public String page1Show(ModelMap map){
return "page1.definition";
}
@RequestMapping("page2.htm")
public String page2Show(){
return "page2.definition";
}
}
general.jsp
=======
<h2>I am General
Body...</h2>
menu.jsp
======
<body>
<a
href="page1.htm">Page1</a>
<a
href="page2.htm">Page2</a>
</body>
footer.jsp
======
<center><h1>@Copy
rights law of India 2016 </h1></center>
header.jsp
=======
<center><h1>My
Tiles Application </h1></center>
page1.jsp
======
Page1
content displayed.
page2.jsp
=======
Page2
content displayed.
web.xml
======
<?xml
version="1.0" encoding="UTF-8"?>
<web-app
version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
No comments:
Post a Comment