{"id":2034,"date":"2011-04-15T15:13:15","date_gmt":"2011-04-15T09:43:15","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=2034"},"modified":"2011-04-15T15:13:15","modified_gmt":"2011-04-15T09:43:15","slug":"tutorial-of-simple-jsp-tiles-application-without-struts","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/tutorial-of-simple-jsp-tiles-application-without-struts\/","title":{"rendered":"Tutorial of Simple JSP Tiles application without Struts"},"content":{"rendered":"<p>There are very few resources available on internet which explains step by step integration of tiles in simple jsp page.<br \/>\n<a title=\"Apache Tiles\" href=\"http:\/\/tiles.apache.org\/\">Apache Tiles\u00e2\u201e\u00a2<\/a> is a templating framework built to simplify the development of web application user interfaces.<\/p>\n<p>Tiles allows authors to define page fragments which can be assembled into a complete page at runtime. 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.<\/p>\n<p><strong>Ste p1 : <\/strong>Download the Tiles jar file from <a title=\"Download Tiles jar file\" href=\"http:\/\/tiles.apache.org\/download.html\" target=\"_blank\">here<\/a>.<!--more--><\/p>\n<p><strong>Step 2 : <\/strong>Add following jar files in the lib folder of the web application.<\/p>\n<blockquote><p>commons-beanutils-1.8.0.jar<br \/>\ncommons-digester-2.0.jar<br \/>\njcl-over-slf4j-1.5.8.jar<br \/>\nlog4j-over-slf4j-1.6.1.jar<br \/>\nservlet-api.jar<br \/>\nslf4j-api-1.5.8.jar<br \/>\nslf4j-jdk14-1.5.8.jar<br \/>\ntiles-api-2.2.2.jar<br \/>\ntiles-core-2.2.2.jar<br \/>\ntiles-jsp-2.2.2.jar<br \/>\ntiles-servlet-2.2.2.jar<br \/>\ntiles-servlet-wildcard-2.2.2.jar<br \/>\ntiles-template-2.2.2.jar<\/p><\/blockquote>\n<p><strong>Step 3: <\/strong>Create following jsp pages:<br \/>\nbanner.jsp, common_menu.jsp, credits.jsp, cssPath.jsp, home_body.jsp and SideBar.jsp.<\/p>\n<p><strong>Step 4: <\/strong>Create a master layout page.<\/p>\n<pre class=\"brush: xml; highlight: [11,15,22,28,38]; title: ; notranslate\" title=\"\">\n&lt;%@ taglib uri=&quot;http:\/\/tiles.apache.org\/tags-tiles&quot; prefix=&quot;tiles&quot;%&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;title&gt;&lt;tiles:getAsString name=&quot;title&quot; \/&gt;\n&lt;\/title&gt;\n&lt;tiles:insertAttribute name=&quot;cssFile&quot;&gt;&lt;\/tiles:insertAttribute&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n\t&lt;div id=&quot;wrapper&quot;&gt;\n\t\t&lt;div id=&quot;menu&quot;&gt;\n\t\t\t&lt;tiles:insertAttribute name=&quot;menu&quot; \/&gt;\n\t\t&lt;\/div&gt;\n\n\t\t&lt;div id=&quot;header&quot;&gt;\n\t\t\t&lt;tiles:insertAttribute name=&quot;header&quot; \/&gt;\n\t\t&lt;\/div&gt;\n\n\t\t&lt;div id=&quot;page&quot;&gt;\n\t\t\t&lt;div id=&quot;page-bgtop&quot;&gt;\n\t\t\t\t&lt;div id=&quot;page-bgbtm&quot;&gt;\n\t\t\t\t\t&lt;div id=&quot;content&quot;&gt;\n\t\t\t\t\t\t&lt;tiles:insertAttribute name=&quot;body&quot; \/&gt;\n\n\t\t\t\t\t\t&lt;div style=&quot;clear: both;&quot;&gt;&amp;nbsp;&lt;\/div&gt;\n\t\t\t\t\t&lt;\/div&gt;\n\n\t\t\t\t\t&lt;div id=&quot;sidebar&quot;&gt;\n\t\t\t\t\t\t&lt;tiles:insertAttribute name=&quot;sideBar&quot; \/&gt;\n\t\t\t\t\t&lt;\/div&gt;\n\n\t\t\t\t\t&lt;div style=&quot;clear: both;&quot;&gt;&amp;nbsp;&lt;\/div&gt;\n\t\t\t\t&lt;\/div&gt;\n\t\t\t&lt;\/div&gt;\n\t\t&lt;\/div&gt;\n\n\t&lt;\/div&gt;\n\t&lt;div id=&quot;footer&quot;&gt;\n\t\t&lt;tiles:insertAttribute name=&quot;footer&quot; \/&gt;\n\t&lt;\/div&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>As you can see, <strong>tiles:insertAttribute<\/strong> tag is used. It will work as placeholder and will be replaced by actual pages at run time as per definition in &#8220;<em><span style=\"text-decoration: underline;\">tiles-defs.xml<\/span><\/em>&#8221;<\/p>\n<p><a title=\"Tiles Tag\" href=\"http:\/\/tiles.apache.org\/migration\/tags.html\">Read more on configuring tiles attributes.<\/a><\/p>\n<p>Below output shows the layout.<\/p>\n<p style=\"text-align: center;\">&nbsp;<\/p>\n<figure id=\"attachment_2037\" aria-describedby=\"caption-attachment-2037\" style=\"width: 463px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/Simple-JSP-Tiles-without-Struts.jpg?ssl=1\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2037  \" title=\"Simple JSP Tiles without Struts\" src=\"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/Simple-JSP-Tiles-without-Struts.jpg?resize=463%2C331&#038;ssl=1\" alt=\"Simple JSP Tiles without Struts\" width=\"463\" height=\"331\" \/><\/a><figcaption id=\"caption-attachment-2037\" class=\"wp-caption-text\">Simple JSP Tiles without Struts<\/figcaption><\/figure>\n<p><strong>Step 5: <\/strong>Now create a &#8220;<em><span style=\"text-decoration: underline;\">tiles-defs.xml<\/span><\/em>&#8221; in WEB-INF Folder, which have all the configuration.<\/p>\n<pre class=\"brush: xml; highlight: [6]; title: ; notranslate\" title=\"\">\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot; ?&gt;\n&lt;!DOCTYPE tiles-definitions PUBLIC\n       &quot;-\/\/Apache Software Foundation\/\/DTD Tiles Configuration 2.1\/\/EN&quot;\n       &quot;http:\/\/tiles.apache.org\/dtds\/tiles-config_2_1.dtd&quot;&gt;\n&lt;tiles-definitions&gt;\n  &lt;definition name=&quot;myapp.homepage&quot; template=&quot;\/layouts\/classic.jsp&quot;&gt;\n    &lt;put-attribute name=&quot;title&quot; value=&quot;Simple Tiles application without Struts&quot; \/&gt;\n    &lt;put-attribute name=&quot;header&quot; value=&quot;\/tiles\/banner.jsp&quot; \/&gt;\n    &lt;put-attribute name=&quot;menu&quot; value=&quot;\/tiles\/common_menu.jsp&quot; \/&gt;\n    &lt;put-attribute name=&quot;body&quot; value=&quot;\/tiles\/home_body.jsp&quot; \/&gt;\n    &lt;put-attribute name=&quot;footer&quot; value=&quot;\/tiles\/credits.jsp&quot; \/&gt;\n    &lt;put-attribute name=&quot;cssFile&quot; value=&quot;\/tiles\/cssPath.jsp&quot; \/&gt;\n    &lt;put-attribute name=&quot;sideBar&quot; value=&quot;\/tiles\/SideBar.jsp&quot; \/&gt;\n  &lt;\/definition&gt;\n&lt;\/tiles-definitions&gt;\n<\/pre>\n<p>The attribute &#8220;name&#8221; defined in tag &#8220;<em><span style=\"text-decoration: underline;\">tiles:insertAttribute<\/span><\/em>&#8221; comes from above configuration file and replaced by the pages specified.<\/p>\n<p><strong>Step 6 :<\/strong> Now create the jsp page which uses the Tiles template defined above.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;%@ page language=&quot;java&quot; contentType=&quot;text\/html; charset=ISO-8859-1&quot;\n    pageEncoding=&quot;ISO-8859-1&quot;%&gt;\n&lt;!DOCTYPE html PUBLIC &quot;-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN&quot; &quot;http:\/\/www.w3.org\/TR\/html4\/loose.dtd&quot;&gt;\n&lt;%@ taglib uri=&quot;http:\/\/tiles.apache.org\/tags-tiles&quot; prefix=&quot;tiles&quot; %&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text\/html; charset=ISO-8859-1&quot;&gt;\n&lt;title&gt;Insert title here&lt;\/title&gt;\n&lt;\/head&gt;\n&lt;body&gt;\n&lt;tiles:insertDefinition name=&quot;myapp.homepage&quot; \/&gt;\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n<p>Template name &#8220;myapp.homepage&#8221; is looked up into file &#8220;<em><span style=\"text-decoration: underline;\">tiles-defs.xml<\/span><\/em>&#8221; and configuration is applied at runtime as per definition.<\/p>\n<blockquote><p><a href=\"https:\/\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/04\/TilesDemo.zip\">Download the war file from here<\/a>, change extension from &#8220;zip&#8221; to &#8220;war&#8221;.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Example of Simple JSP Tiles application without Struts<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[4],"tags":[125],"class_list":["post-2034","post","type-post","status-publish","format-standard","hentry","category-jsp","tag-j2ee"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1707,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/setup-application-to-use-javaserver-pages-standard-tag-libraryjstl\/","url_meta":{"origin":2034,"position":0},"title":"Setup application to use JavaServer Pages Standard Tag Library(JSTL)","author":"Jitendra","date":"March 17, 2011","format":false,"excerpt":"Setup application to use JavaServer Pages Standard Tag Library(JSTL)","rel":"","context":"In &quot;JSP&quot;","block_context":{"text":"JSP","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/jsp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1664,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/step-by-step-dwr-application-simple-ajax-in-java\/","url_meta":{"origin":2034,"position":1},"title":"Step by Step DWR Application &#8211; Simple AJAX in JAVA","author":"Jitendra","date":"March 15, 2011","format":false,"excerpt":"Step by Step DWR Application - Simple AJAX in JAVA","rel":"","context":"In &quot;JSP&quot;","block_context":{"text":"JSP","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/jsp\/"},"img":{"alt_text":"How DWR works in Java","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/How-DWR-works-in-Java.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1720,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/how-to-create-jsp-custom-tag-using-tag-interface-or-tagsupport\/","url_meta":{"origin":2034,"position":2},"title":"How to Create JSP Custom Tag \u2013 using Tag interface or TagSupport","author":"Jitendra","date":"March 17, 2011","format":false,"excerpt":"Tutorial of creating JSP Custom Tag \u2013 using Tag interface or TagSupport in JAVA","rel":"","context":"In &quot;JAVA&quot;","block_context":{"text":"JAVA","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/"},"img":{"alt_text":"How to Create Custom Tag in JSP","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/How-to-Create-Custom-Tag-in-JSP.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1834,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/struts\/step-by-step-simple-login-application-in-struts-2\/","url_meta":{"origin":2034,"position":3},"title":"Step by Step Simple Login Application in Struts 2","author":"Jitendra","date":"March 24, 2011","format":false,"excerpt":"Example of Simple Login Application in Struts 2","rel":"","context":"In &quot;Struts&quot;","block_context":{"text":"Struts","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/struts\/"},"img":{"alt_text":"Final Structure of Struts 2 login application","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Final-Structure-of-Struts-2-login-application.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1460,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/setting-session-timeout-in-jsp-servlet\/","url_meta":{"origin":2034,"position":4},"title":"Setting Session Timeout in JSP Servlet","author":"Jitendra","date":"February 7, 2011","format":false,"excerpt":"How to set the Session Time out in JSP and Servlet","rel":"","context":"In &quot;JSP&quot;","block_context":{"text":"JSP","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/jsp\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1643,"url":"https:\/\/www.jitendrazaa.com\/blog\/java\/jsp\/servlet-hibernate-jquery-and-ajax-based-google-like-chat\/","url_meta":{"origin":2034,"position":5},"title":"Servlet, Hibernate, jQuery and Ajax based google like chat","author":"Jitendra","date":"March 14, 2011","format":false,"excerpt":"Servlet, Hibernate, jQuery and Ajax based google like chat with source code","rel":"","context":"In &quot;Hibernate&quot;","block_context":{"text":"Hibernate","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/java\/hibernate\/"},"img":{"alt_text":"Servlet, Hibernate, jQuery and Ajax based google like chat","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/03\/Servlet-Hibernate-jQuery-and-Ajax-based-google-like-chat.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2034","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=2034"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/2034\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=2034"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=2034"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=2034"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}