Friday, July 2, 2010

Struts2 Data control Text tag Example


Struts2 Text Tag Example


Aim:
Text tag is a generic tag that is used to get values from properties. The properties file is saved where the java file is saved.

There are three ways to use text tag.

1). To get values from *.properties file

2). If the body of the text tag is not specified, the name of the text tag will display.

3). If the body of the text tag is specified, the body of the tag will display.


Procedure:

          Step 1:

          Create Project name as DataTextPro

          Step 2:

          Create Action as HelloWorld.java

          Include following coding within the


package example;

import com.opensymphony.xwork2.ActionSupport;

public class HelloWorld extends ActionSupport
{

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

Step 3:

Create jsp file

HelloWorld.jsp



< %@ page contentType="text/html; charset=UTF-8" % >

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

< html >
< head >
< title > Text tag Example < / title >

< /head >

< body >
< s:text name="body not.message" > < /s:text >


< s:text name="message" > sureshkumar, welcome< /s:text >


< /body >
< /html >

Step 4:

Made some changes 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="example" namespace="/example" extends="struts-default" >
< action name="textAction" class="example.HelloWorld" >
< result > /example/HelloWorld.jsp < /result >
< /action >
< /package >
< /struts >


Step 5:

          Run the HelloWorld.jsp

Directory structure of the project

No comments:

Post a Comment