Sunday, July 4, 2010

Struts2 Data Control Include Tag Example


Struts2 Include Tag Example

Aim:
            The include tag is used to include servlet or jsp into the current page.

Procedure:

            Step 1:

            Create Project as  IncludePro

            Step 2:

            Create Action as IncludeAction.java

package example;
import com.opensymphony.xwork2.ActionSupport;

public class IncludeAction extends ActionSupport
{

    public IncludeAction()
    {
    }

    public String execute() throws Exception
    {
       return "success";
    }

}

Step 3:

Create jsp file

1). home.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >

< title > home JSP Page < /title >
< /head >
< body >
< s:form action="includeAction" >
< s:submit/ >
< /s:form >
< /body >
< /html >

2). success.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >

< title > success JSP Page < /title >
< /head >
< body >
< s:include value="display.jsp"/ >
< /body >
< /html >

3). display.jsp



< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >

< title > success JSP Page < /title >
< /head >
< body >
SureshKumar.,M.Sc,M.Phil.,
< /body >
< /html >


Step 4:

Made some chages in struts.xml


< !DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
http://struts.apache.org/dtds/struts-2.0.dtd >

< struts >

< package name="default" extends="struts-default" >
< action name="includeAction" class="example.IncludeAction" >
< result name="input" < /example/home.jsp < /result >
< result name="success" > /example/success.jsp < /result >

< /action >
< /package >
< /struts >


Step 5:

Run the home.jsp

Directory structure of the project

No comments:

Post a Comment