Struts 2.x Tiles Framework (Netbeans IDE) – Part(2)

Before starting with this post make sure you are aware of the things mentioned in my previous post and pages i.e.:

1. Struts 2.x Netbeans IDE Setup
2. Struts 2.x Tiles Framework (Netbeans IDE) – Part(1)

Now, considering that you have already gone through the above two specified links lets move to our first web project in Struts 2.x using Tiles integration.

Here is what we have to create and have a directory look:

So, starting from the beginning lets follow step by step to complete this project:

1. Open tiles.xml (If you haven’t created yet follow my previous section of ref. posts)

Put these contents there and remove all the previous ones:

2. Open web.xml (If you haven't created yet follow my previous section of ref. posts)

Put these contents there and remove all the previous ones:

struts2
        org.apache.struts2.dispatcher.FilterDispatcher
        org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG
        /WEB-INF/tiles.xml
        org.apache.struts2.tiles.StrutsTilesListener
3. Open struts.xml file (see the above image and make sure this file appears under configurations file category. If it is not there you might have not selected struts 2 at the time of new project creation or your IDE is missing struts2 plugin support. For any of this visit our strust2 introduction page)

Put these contents there and remove all the previous ones:

 index.jsp
 about.def
  contact.def
 
4. Open index.jsp or Create if not present

Put these contents in the file there:

<%-- Document : index Created on : Sep 8, 2012, 8:39:16 PM Author : Sudhanshu --%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="t" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

 5. Create menu.jsp page
<%-- Document : menu Created on : Sep 8, 2012, 8:45:53 PM Author : Sudhanshu --%>
<%@taglib uri="/struts-tags" prefix="s" %>

Home
About
Contact 

6. Create template.jsp page

<%-- Document : template Created on : Sep 8, 2012, 8:41:43 PM Author : Sudhanshu --%>
<%@taglib uri="http://tiles.apache.org/tags-tiles" prefix="t" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
 
 
 
 
 

7. Create body.jsp page

Write some lines there... e.g.:

This is the home page!!!

8. Create header.jsp page

Write some lines there... e.g.:

  Header

9. Create footer.jsp page

Write some lines there... e.g.:

Footer

10. Create about.jsp page

Write some lines there... e.g.:

This is about the project!!

11. Create contact.jsp page

Write some lines there... e.g.:

This is the contact page!!!

To Run :

Right Click on the project starting directory e.g WebApplication1, which can be seen in the topmost image. Click on run and see the functionality of Struts 2.x Tiles Framework.