I have a Tiles layout page having Header, Menu, Body. In this layout whenever user does some action in the Menu lists, the whole Layout is refreshing. I want header,menu to be static, and only body part should get refresh.
Is there any way to prevent the refresh of the Header, menu and update only Body content on the menu click which can be implemented using Spring Tiles?
I got some same question but its related to structs. i don't have idea about structs
If anybody give piece of code it will be helpful.
(1)write this tiles configuration into spring xml file.
<bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver"/>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/layouts/layouts.xml</value>
<value>/WEB-INF/layouts/views.xml</value>
</list>
</property>
</bean>
(2)layouts.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="DefaultTemplate" template="/WEB-INF/views/template/SiteTemplate.jsp">
<put-attribute name="title" value="Home" />
<put-attribute name="header" value="/WEB-INF/views/template/header.jsp" />
<put-attribute name="menu" value="/WEB-INF/views/template/menu.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/views/template/footer.jsp" />
</definition>
</tiles-definitions>
(3)views.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="index" extends="DefaultTemplate">
<put-attribute name="body" value="/WEB-INF/views/index.jsp" />
</definition>
<definition name="personList" extends="DefaultTemplate">
<put-attribute name="body" value="/WEB-INF/views/personList.jsp" />
</definition>
</tiles-definitions>
(4)SiteTemplate.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Spring MVC - Tiles Integration tutorial</title>
<link rel="stylesheet" href="resources/css/screen.css" type="text/css" media="screen, projection"></link>
<link rel="stylesheet" href="resources/css/print.css" type="text/css" media="print"></link>
<!--[if IE]>
<link rel="stylesheet" href="resources/css/ie.css" type="text/css" media="screen, projection">
<![endif]-->
<style>
body{ margin-top:20px; margin-bottom:20px; background-color:#DFDFDF;}
</style>
</head>
<body>
<div class="container" style="border: #C1C1C1 solid 1px; border-radius:10px;">
<!-- Header -->
<tiles:insertAttribute name="header" />
<!-- Menu Page -->
<div class="span-5 border" style="height:400px;background-color:#FCFCFC;">
<tiles:insertAttribute name="menu" />
</div>
<!-- Body Page -->
<div class="span-19 last">
<tiles:insertAttribute name="body" />
</div>
<!-- Footer Page -->
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>
(5)menu.jsp
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<ul style="list-style:none;line-height:28px;">
<li><spring:url value="/index" var="homeUrl" htmlEscape="true" />
Home
</li>
<li><spring:url value="/viewPeson" var="personListUrl" htmlEscape="true" />
Person List
</li>
</ul>
(6)same as write footer.jsp and header.jsp for your requirement.
(7)code for controlller
#RequestMapping(value="index")
public String index() {
return "index";
}
**NOTE:return type value is same as definition name in views.xml**
Related
I'm using Tiles for the first time. Trying to layout my JSP pages in my Spring MVC project.
Please take a look at what I'm doing and let me know if this is the "correct" way to do it ... my specific question is at the bottom ...
I have the file structured like this ... folder /src/main/webapp/WEB-INF/layouts/ contains ...
standard.jsp
// ...
<html>
<title><tiles:insertAttribute name="title"/></title>
// ... LOTS OF HTML ...
<tiles:insertAttribute name="header"/>
<tiles:insertAttribute name="body"/>
<tiles:insertAttribute name="footer"/>
// ... LOTS OF HTML
</html>
// ...
tiles.xml
<tiles-definitions>
<definition name="standardLayout" template="/WEB-INF/layouts/standard.jsp">
<put-attribute name="title" value="My Directory" />
<put-attribute name="header" value="/WEB-INF/layouts/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="" />
</definition>
</tiles-definitions>
And my viewable JSPs are in folder /src/main/webapp/WEB-INF/views/ which contains ...
tiles.xml
<tiles-definitions>
<definition name="home" extends="standardLayout">
</definition>
</tiles-definitions>
home.jsp
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<tiles:insertDefinition name="home">
<tiles:putAttribute name = "body" value="/WEB-INF/views/home-body.jsp"/>
</tiles:insertDefinition>
home-body.jsp
<div>
// LOTS OF HTML FOR THE BODY OF THE HOME PAGE
</div>
QUESTIONS: I'd like to just have one home.jsp but it looks like I have to pull the body content (and any other content) from a separate file. Is there an appropriate way to simplify home.jsp and home-body.jsp into one file, or am I actually doing this all correctly?
You need to update your tiles.xml, standard.jsp and home.jsp as below,
tiles.xml
<tiles-definitions>
<definition name="home" extends="standardLayout">
<put-attribute name="body" value="/WEB-INF/views/home.jsp"></put-attribute>
</definition>
</tiles-definitions>
standard.jsp
<html>
<title><tiles:insertAttribute name="title"/></title>
<header>
<tiles:insertAttribute name="header"/>
</header>
<body>
<tiles:insertAttribute name="body"/>
</body>
<footer>
<tiles:insertAttribute name="footer"/>
</footer>
</html>
home.jsp
<!-- Actual body content goes here.. -->
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<p>The content of the home page.</p>
I have searched for this but didn't get the solution for the same. I got information i.e. we have to use <mvc:resources location="/resources/" mapping="/resources/**"/> and place all the static member like css/img/js inside resources folder
src
|--main
| |
| |--java
| |--resources
| |--webapp
And then we have to use either jstl or spring tags to map the resources as below:
<head>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<spring:url value="/resources/LoginForm.css" var="loginCss" />
<link rel="stylesheet" href="${loginCss}" type="text/css" />
</head>
I have developed some code by keeping all the points in mind but getting 404 error for static resources.
click here for project structure
code for dispatcher servlet.xml
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
">
<mvc:annotation-driven/>
<context:component-scan base-package="com.anand" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="/WEB-INF/messages" />
</bean>
<mvc:resources location="/resources/" mapping="/resources/**"/>
<mvc:default-servlet-handler />
</beans>
Code for loginform.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Home-Login</title>
<spring:url value="/resources/LoginForm.css" var="loginCss" />
<spring:url value="/resources/logo1.PNG" var="logo1" />
<spring:url value="/resources/img1.png" var="img1" />
<spring:url value="/resources/img2.png" var="img2" />
<spring:url value="/resources/img3.png" var="img3" />
<link rel="stylesheet" href="${loginCss}" type="text/css" />
</head>
<body class="login">
<!-- header starts here -->
<div id="facebook-Bar">
<div id="facebook-Frame">
<div id="logo"> <img src="${logo1}" /></div>
<div id="header-main-right">
<div id="header-main-right-nav">
<form:form action="loginform.html" method="post" commandName="loginform">
<table border="0" style="border:none">
<tr>
<td ><form:input type="text" tabindex="1" path="userName" placeholder="UserName" class="inputtext radius1" value="" /></td>
<td ><form:input type="password" tabindex="2" path="password" placeholder="Password" class="inputtext radius1" /></td>
<td ><input type="submit" class="fbbutton" name="login" value="Login" /></td>
</tr>
<tr>
<td><label>
<input id="persist_box" type="checkbox" name="persistent" />
<span style="color:#ccc;">Keep me logged in</span></label></td>
<td><label>forgot your password?</label></td>
</tr>
</table>
</form:form>
</div>
</div>
</div>
</div>
<div class="slideshow-container" style="width:100%;height:80%; min-width:1000px;">
<div class="mySlides fade" style="width:100%;height:100%">
<div class="numbertext">1 / 3</div>
<img src="${img1}" style="width:100%;height:100%" />
<div class="text">Caption Text</div>
</div>
<div class="mySlides fade" style="width:100%;height:100%">
<div class="numbertext">2 / 3</div>
<img src="${img2}" style="width:100%;height:100%" />
<div class="text">Caption Two</div>
</div>
<div class="mySlides fade" style="width:100%;height:100%">
<div class="numbertext">3 / 3</div>
<img src="${img3}" style="width:100%;height:100%" />
<div class="text">Caption Three</div>
</div>
</div>
<br/>
<div style="text-align:center">
<span class="dot"></span>
<span class="dot"></span>
<span class="dot"></span>
</div>
<script>
var slideIndex = 0;
showSlides();
function showSlides() {
var i;
var slides = document.getElementsByClassName("mySlides");
var dots = document.getElementsByClassName("dot");
for (i = 0; i < slides.length; i++) {
slides[i].style.display = "none";
}
slideIndex++;
if (slideIndex> slides.length) {slideIndex = 1}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" active", "");
}
slides[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " active";
setTimeout(showSlides, 2000); // Change image every 2 seconds
}
</script>
</body>
</html>
When it redirects me to loginform.jsp and i do F12-->network analysis, it shows me 404 for static resources like ,img1,img2,img3,logo1 and for .css file.
Click Here for F12 debug and chrome view of page without css
[[Solved]]: Finally solved the problem but i'm not sure the approach i have used here is correct or not but yeah it's working for me. Solution: i have copied the resources folder under webapp folder (i.e. WEB_INF & resources are siblings).
Click here for updated directory structure image
Please do provide better solution of this if you have for the same:
Resources inside WEB-INF are protected to be not accessible directly from the client.
In general, if it is static resources such as html, CSS, JavaScript can be placed outside WEB-INF. Static content placed outside can be therefore downloaded directly from the client browser.
Pls read Referencing a resource placed in WEB-INF folder in JSP file returns HTTP 404 on resource
I'm using Apache Tile in Spring Web App,
I have to include some dependencies under certain conditions,
So I want to know if in file "tiles.xml" we can set some conditions as below ?
<definition name=".tpl1" extends=".MainTpl"
template="/WEB-INF/views/templates/tpl1.jsp">
<put-attribute name="header" value="XX" />
<put-attribute name="dashboard" value="XX" />
<if [Some condition] >
<put attribute name="isOk" value="XX />
/>
<else>
<put-attribute name="isNok" value="YY" />
/>
</definition>
I'm really not sure about this part but I want to know if it's possible or not :)
Kind regards :)
There is no condition in Apache Tiles. Instead you can compose your definition like this :
<definition name=".tpl1" extends=".MainTpl"
template="/WEB-INF/views/templates/tpl1.jsp">
<put-attribute name="header" value="XX" />
<put-attribute name="dashboard" value="XX" />
<put-attribute name="condition" value="condition.jsp" />
<put-attribute name="isOk" value="XX" />
<put-attribute name="isNOk" value="XX" />
</definition>
And in condition.jsp have something like this
<%# page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<c:choose>
<c:when test="[some condition]">
<tiles:insertAttribute name="isOk">
</c:when>
<c:otherwise>
<tiles:insertAttribute name="isNOk">
</c:otherwise>
</c:choose>
Your question is very similar to this, you can refer to the answer there.
I'm trying to use Spring MVC 3.2.4 & Tiles 3.0.1 with Regexp prefixes in my tiles.xml file. I'm a newbie with Tiles, so I might be doing something wrong, but have been trying to follow things I have read on in the Tiles doc site as well as apply stuff from the tech.finn.no blog.
Unfortunately, when I use completeAutoLoad=true with RegExp prefix in my tiles.xml file, I get stuck in an infinite loop when trying to resolve the view.
Stack Trace:
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.StackOverflowError
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
....
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at org.springframework.security.web.context.SaveContextOnUpdateOrErrorResponseWrapper.encodeURL(SaveContextOnUpdateOrErrorResponseWrapper.java:181)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
....
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at javax.servlet.http.HttpServletResponseWrapper.encodeURL(HttpServletResponseWrapper.java:76)
at org.springframework.web.servlet.tags.UrlTag.createUrl(UrlTag.java:227)
at org.springframework.web.servlet.tags.UrlTag.doEndTag(UrlTag.java:174)
at org.apache.jsp.tag.webutil.load_002dscripts_tag._jspx_meth_spring_005furl_005f0(load_002dscripts_tag.java:300)
at org.apache.jsp.tag.webutil.load_002dscripts_tag.doTag(load_002dscripts_tag.java:113)
at org.apache.jsp.WEB_002dINF.views.tiles.layouts.default_jsp._jspx_meth_util_005fload_002dscripts_005f0(default_jsp.java:176)
at org.apache.jsp.WEB_002dINF.views.tiles.layouts.default_jsp._jspService(default_jsp.java:93)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:749)
pom.xml:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.1</version>
</dependency>
webmvc-config.xml:
<bean class="org.springframework.web.servlet.view.tiles3.SpringWildcardServletTilesApplicationContext" autowire="constructor" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.tiles3.TilesViewResolver" >
<property name="cache" value="false"/>
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
</bean>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="completeAutoload" value="true"/>
</bean>
Tiles.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="REGEXP:(.+)" template="/WEB-INF/views/tiles/layouts/default.jsp">
<put-attribute name="meta" value="/WEB-INF/views/tiles/{1}/meta.jsp"/>
<put-attribute name="head" value="/WEB-INF/views/tiles/{1}/head.jsp"/>
<put-attribute name="header" value="/WEB-INF/views/tiles/{1}/header.jsp"/>
<put-attribute name="menu" value="/WEB-INF/views/tiles/{1}/menu.jsp"/>
<put-attribute name="body" value="/WEB-INF/views/tiles/{1}/body.jsp"/>
<put-attribute name="footer" value="/WEB-INF/views/tiles/{1}/footer.jsp"/>
</definition>
</tiles-definitions>
default.jsp:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib prefix="util" tagdir="/WEB-INF/tags/util"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<jsp:directive.page pageEncoding="UTF-8" />
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<tiles:insertAttribute name="meta" ignore="true" />
<util:load-scripts />
<tiles:insertAttribute name="head" ignore="true" />
<spring:message code="application_name" var="app_name" htmlEscape="false"/>
<title><spring:message code="welcome_h3" arguments="${app_name}" /></title>
</head>
<body class="tundra spring">
<div id="wrapper">
<div id="header"><tiles:insertAttribute name="header" ignore="true" /></div>
<div id="menu"><tiles:insertAttribute name="menu" ignore="true" /></div>
<div id="main">
<div id="body"><tiles:insertAttribute name="body"/></div>
<div id="footer"><tiles:insertAttribute name="footer" ignore="true"/></div>
</div>
</div>
</body>
</html>
/WEB-INF/views/tiles/secure/login/body.jsp:
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%# taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%# taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%# taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%# taglib prefix="util" tagdir="/WEB-INF/tags/util"%>
<jsp:directive.page contentType="text/html;charset=UTF-8" />
<div class="container">
<form name="login" class="form-signin" action='<spring:url value="/j_spring_security_check"/>' method="POST">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="form-control" name="j_username" placeholder="Email address" autofocus>
<input type="password" class="form-control" name="j_password" placeholder="Password">
<label class="checkbox"> <input type="checkbox" value="remember-me"> Remember me</label>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
I don't think there is anything specifically special in this configuration, so am not sure why I get into an infinite loop. If I replace the CompleteAutoTilesInitializer class with the BasicTilesInitializerClass and use Wildcards (ie: /) instead and replace {1} with {1}/{2}, then the view loads properly (no infinite loop).
Any ideas what I am doing wrong, or is this a Tiles problem?
Found a similar SO issue (https://stackoverflow.com/a/6617343/827480) that pointed out that the regexp is too greedy and tries to match all attributes as well forever, hence causing the StackOverflow. Work around at the moment is to use a less greedy regexp.
Getting some traction under https://issues.apache.org/jira/browse/TILES-572 and http://thread.gmane.org/gmane.comp.apache.tiles.user/612
I'm brand new to Tiles so this is probably a very easy question. I've created a web application using Java / Spring 3 / JSPs without the use of tiles and now I'm realizing my life would be much easier with it.
I'm a bit confused on one aspect thus far, and that's defining the layouts. My problem is that in examples I've seen online you define a layout.jsp which contains the information (including tags and tags).
My question is, the "layout.jsp" file is supposed to be the generic "one-size-fits-all" type of file, but what happens when I create another file (say welcome.jsp) which should USE the layout template, but I need to define more and tags... if I define them inside of the welcome.jsp file then the rendered JSP file is not formatted correctly... i.e:
<head>
<!-- This is content from the layout.jsp file -->
<title>Welcome</title>
<link rel="shortcut icon" href="images/favicon.ico"/>
<script type="text/javascript">
// some javascript
</script>
</head>
<body>
<!-- This is content from the welcome.jsp file which is malformed -->
<head>
<script src="js/jquery.mousewheel.min.js"></script>
</head>
</body>
Any help would be greatly appreciated.
Here's my 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="baseLayout" template="/WEB-INF/jsp/layout/layout.jsp">
<put-attribute name="title" value="" />
<put-attribute name="header" value="/WEB-INF/jsp/layout/header.jsp" />
<put-attribute name="body" value="" />
<put-attribute name="footer" value="/WEB-INF/jsp/layout/footer.jsp" />
</definition>
<definition name="videos" extends="baseLayout">
<put-attribute name="title" value="Videos" />
<put-attribute name="body" value="/WEB-INF/jsp/videos.jsp" />
</definition>
</tiles-definitions>
layout.jsp
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%# include file="../tracking.jsp" %>
<!DOCTYPE HTML>
<html>
<head>
<title><tiles:insertAttribute name="title" ignore="true" /></title>
<link rel="shortcut icon" href="images/favicon.ico"/>
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="css/jquery-ui-1.10.css" media="screen" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
</head>
<body>
<tiles:insertAttribute name="header" />
<tiles:insertAttribute name="body" />
<tiles:insertAttribute name="footer" />
</body>
</html>
Create a new definition to change the header content:
<definition name="baseLayout" template="/WEB-INF/jsp/layout/layout.jsp">
<!-- Defined here -->
<put-attribute name="head" value="" />
<put-attribute name="title" value="" />
...
</definition>
<definition name="videos" extends="baseLayout">
<!-- Overridden here -->
<put-attribute name="head" value="/WEB-INF/jsp/videos-additionalHeadDefinitions.jsp" />
...
</definition>
And add this to you layout.jsp:
<head>
<!-- This is content from the layout.jsp file -->
<title>Welcome</title>
...
<tiles:insertAttribute name="head" />
</head>