By: Fazal in Struts Tutorials on 2003-05-04
IncludeAction is a Struts action class that is used to include the content of one JSP page within another JSP page. It is typically used when you have common content that you want to reuse across multiple JSP pages, such as a header or footer.
IncludeAction class extends the
org.apache.struts.action.Action class and provides a method named
execute() that is invoked when the action is called. The method includes the content of the specified JSP page using the
Here's an example of using the
IncludeAction in Struts:
- Define an action in your
<action path="/includeExample" type="org.apache.struts.action.IncludeAction"> <forward name="success" path="/WEB-INF/jsp/include-example.jsp"/> </action>
- Create a JSP page that contains the content you want to include:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Include Example</title> </head> <body> <h1>Header</h1> <p>This is the header content.</p> </body> </html>
- Create another JSP page that includes the first page using the
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="html" uri="http://struts.apache.org/tags-html" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Include Example</title> </head> <body> <html:form action="/includeExample"> <html:submit value="Include"/> </html:form> <br/><br/> <h1>Page Content</h1> <p>This is the page content.</p> <html:include page="/include-example.jsp"/> <h1>Footer</h1> <p>This is the footer content.</p> </body> </html>
In this example, the
IncludeAction is used to include the content of the
include-example.jsp page within the main JSP page. The
html:include tag is used to specify the page to include.
Note that the
IncludeAction is not commonly used in modern web development, as most developers now prefer to use template engines or server-side includes to achieve the same functionality.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Struts )
Latest Articles (in Struts)
- Data Science
- React Native
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews