Showing posts with label UITAGS-1. Show all posts
Showing posts with label UITAGS-1. Show all posts

Saturday, June 12, 2010

Struts2-UI TAGS-II


Struts2-UI-TAGS-II

Aim:
            We will learn the combobox and radio button and reset.


Procedure:

            Step 1:

            Create project for struts2.

            Step 2:
           
            Create Action class

            Step 3:

            Made some changes in struts.xml

            Step 4:

            Create home.jsp and display.jsp file

            Step 5:

            Run the home.jsp file
  
Step 1:

            Create project name as UI-tag II
 
Open the netbean 6.8

File—New Project New Project window will open.

Select java web under categories and select web Application under Projects.

Next

New Web Application window will open.

Give project name ( UI-Tags-II)
Next and also Next

Select Framework

You select struts2

Finish

The project UI-Tags-II has created successfully.

NOTE:

            Delete all files under example folder for web pages and source packages

Structure of the Struts2 Project


















Note:

            Store all jsp files under web pages

            Store all action class under sources packages


Step 2:

            Create Action class name as uiaction

Right click on example under Source Packages

New—Other—select Struts2 under categories and select Struts2 Action under File types.

Next

Give Action class name (uiaction)

Finish

The Action class uiaction has created successfully.


Include following coding into uiaction


package example;

import com.opensymphony.xwork2.ActionSupport;
public class uiaction extends ActionSupport
{
    /* combo box */
    private String country;

    /* radio button */
    private String sex;

    public String getSex()
    {
        return sex;
    }

    public void setSex(String sex)
    {
        this.sex = sex;
    }

    /* check box */
    public String getCountry()
    {
        return country;
    }
    public void setCountry(String country)
    {
        this.country = country;
    }
    public uiaction()
    {
    }
    public String execute() throws Exception
    {
        return "success";
    }
}

Step 3:

            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="uiaction" class="example.uiaction" >
< result name="success" > /example/display.jsp < /result >
< result name="input" > /example/home.jsp < /result >
< /action >

< /package >
< /struts >

Step 4:

Create home.jsp


< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< title > JSP Page < /title >
< /head >
< body >
< s:form action="uiaction" method="post" >
< s:combobox label="Country" name="country"
list="{'India','Japan','England','Australia','Newzeland'}"
headerValue="--Select Country--"
headerKey="1"/ >

< s:radio label="Sex" list="{'Male','FeMale'}" name="sex"/ >


< s:submit value="OK"/ >

< s:reset label=”Clear” / >
< /s:form >
< /body >
< /html >

Create display.jsp

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

< title > JSP Page < /title >
< /head >
< body >
Country:< s:property value="country"/ >
< br >
Sex: < s:property value="sex"/ >
< br >

< /body >
< /html >


Step 5:

Run the display.jsp

Thursday, June 10, 2010

Struts2-UI TAGS-I


Struts2-UI Tags Example-I

AIM:

To understand how to use some UI tags such as label, textfield, password, form, submit.

Problem:

Create textfield for username and create password for password.

If you give correct username and password , the display.jsp file will display.

Otherwise the failure.jsp will display.

PROCEDURE:

Step 1:

            Create project Named UITags-I

Step 2:

            Create Action class named UIAction

            Include following coding into UIAction

package example;
import com.opensymphony.xwork2.ActionSupport;
public class UIAction extends ActionSupport
{
    private String username;
    private String password;

    public String getPassword()
    {
        return password;
    }

    public void setPassword(String password)
    {
        this.password = password;
    }

    public String getUsername()
    {
        return username;
    }

    public void setUsername(String username)
    {
        this.username = username;
    }

    public UIAction()
    {
    }

    public String execute() throws Exception
    {
       if((getUsername().equals("suresh"))&&(getPassword().equals("kumar")))
       {
           return "success";
       }
       else
       {
           return "failure";
       }

    }

}

Step 3:

            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="uiaction" class="example.UIAction" >
< result name="input" > /example/register.jsp < /result >
< result name="success" > /example/display.jsp < /result >
< result name="failure" > /example/failure.jsp < /result >
< /action >
< /package >
< /struts >


Step 4:

Create register.jsp

Include following code into register.jsp


< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< title > Register Page < /title >
< /head >
< body >
< s:form action="uiaction" method="post" >
< s:textfield name="username" label="UserName"/ >
< s:password name="password" label="PassWord"/ >
< s:submit value="OK"/ >
< /s:form >
< /body >
< /html >


Step 5:

            Create display.jsp


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

< h1 > WELCOME < /h1 > < h2 > < s:property value="username" > < /s:property > < /h2 >

< /body >
< /html >


Step 6:

            Create failure.jsp

< %@taglib uri="/struts-tags" prefix="s" % >
< html >
< head >
< title > Register Page < /title >
< /head >
< body >
< h1 > Hello ! < s:property value="username"/ > -- Who Are You? < /h1 >
< h2 > Enter Correct Username and password < /h2 >
< /body >
< /html >


Step 7:

            Run register.jsp

Conclusion:

            Form this , we have understood how to use textfield, password and form and submit tags.

Directory Structure of this project