We can customize the layout of the struts 2 application by integrating with tiles framework.
A web page can contain many parts (known as tile) such as header, left pane, right pane, body part, footer etc. In tiles framework, we manage all the tile by our Layout Manager page.
There are following advantages of tiles framework:
The steps are as follows:
If you are using myeclipse IDE, you can add tiles library by right click on the project -> Build Path -> Add Library -> Add Myeclipse Library -> Select the Struts 2 tiles library -> ok.
If you are using eclipse or Netbeans IDE, you need to add the required tiles library in your project.
Provide entry of listener class Struts2TilesListener in the web.xml file.
web.xml
This action class contains one field name and defines the execute method.
Login.java
This xml file defines one package with one action and two results.
struts.xml
The tiles.xml file must be located inside the WEB-INF directory.
tiles.xml
It is the layout manager page. It used getAsString tag of tiles to include the string resource and insertAttribute tag of tiles to include the page resource.
layoutmanager.jsp
There are many view components such as header.jsp, footer.jsp, welcome.jsp etc.
header.jsp
footer.jsp login-success.jspPassword is not admin, so error page will be displayed.
If password is admin, success page will be displayed.
To define multiple tiles, you need to add following entry in your web.xml file.