<s:include>:
The <s:include> tag is used to include the result of any other resource. Other resource can be JSP, HTML or servlet etc. It acts similar to the jsp include.
Syntax:
<s:include value=”resourceUrl”/>
Note: It can take parameters using s:param tag.
Example:
test.jsp
<%@ taglib uri="/struts-tags" prefix="s"%> <html> <head> <title>Struts 2 s:include data tag example</title> </head> <body> <h3>This is a s:include data tag example.</h3> <s:include value="welcome.jsp"/> </body> </html> |
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>struts2</filter-name> <filter-class> org.apache.struts2.dispatcher.ng. filter.StrutsPrepareAndExecuteFilter </filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>test.jsp</welcome-file> </welcome-file-list> </web-app> |
welcome.jsp
<%@ taglib uri="/struts-tags" prefix="s"%> <html> <head></head> <body> <h3>This content is of the included file.</h3> </body> </html> |
Output:
Download this example.
Next Topic: Struts 2 bean data tag with example.
Previous Topic: Struts 2 action tag with example.