Last Updated At 2020-06-15

Struts Zero Configuration:We can make struts 2 application without the arrangement record struts.xml. There are two approaches to make Struts zero Configuration."http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaeehttp://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">index.jsp struts2 struts2 /* org.apache.struts2.tiles.StrutsTilesListener 3) Create the input page (index.jsp) index.jsp:<%@ taglib uri="/struts-tags" prefix="s" %><s:form action="login"><s:textfield name="name" label="Name">s:textfield><s:password name="password" label="Password">s:password><s:submit value="login">s:submit>s:form>4) Create the action classlogin-success login-error 6) Create the tiles.xml file and define all the tiles definitions tiles.xml 7) Create the LayoutManager pagelayoutmanager.jsp<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>> <%@ include file="header.jsp" %> <%@ include file="footer.jsp" %>8) Create View componentsheader.jsp
footer.jsp
- By convention
- By annotation
- Create input page (optional)
- Create the action class
- Create view components
Struts 2 give you advantageous approach to make struts application utilizing comments. Thus, there is no need struts.xml document. As we have said before, there are 2 approaches to utilize zero arrangement document (no struts.xml record).
- By convention
- By annotation
- @Action annotation is utilized to stamp the activity class.
- @Results annotation is utilized to characterize numerous outcomes for one activity.
- @Result annotation is utilized to show single outcome.
Tiles Framework Integration:
We can customize the design of the struts 2 application by incorporating with tiles structure. A site page can contain many parts (known as tile, for example, header, left sheet, right sheet, body part, footer and so on. In tiles system, we deal with all the tile by our Layout Manager page.
Advantage of tiles
- Customization
- Code reusability
- Easy to modify
- Easy to remove
Steps to create tiles application
- Add tiles library in your application
- Define Struts2TilesListener in web.xml file
- Create the input page (index.jsp)
- Create the Action class
- Extend the tiles-default package in your package and define all the result type as tiles in struts.xml file
- Create the tiles.xml file and define all the tiles definitions
- Create the LayoutManager page
- Create the View components
1) Add tiles library in your application
By using myeclipse IDE, we can add tiles by right click on the project -> Build Path -> Add Library -> Add Myeclipse Library -> Select tiles -> then ok.2) Define Struts 2 Tiles Listener in web.xml file.
web.xml;Login.java:
package com.javaspot;public class Login {private String name,password;//getters and setterspublic String execute(){if(password.equals("admin")){return "success";}else{return "error";}}}5) Inherit the tiles-default package and define all the result type as tiles in struts.xml struts.xml- xmlversion="1.0" encoding="UTF-8" ?>
- "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
- "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
It is header tile
footer.jsp
It is footer tile
login-success.jsp<%@ taglib uri="/struts-tags" prefix="s" %>Welcome,login-error.jsp