Struts2.2.1 UI tag example.
Posted on: January 17, 2011 at 12:00 AM
In this section, you will see the use of struts UI tag.

Struts2.2.1 UI tag example.

In this tutorial, you will see the use of some UI_ tags of struts framework.

 1- index.jsp

<html>ADS_TO_REPLACE_1

<head><title>Struts2.2.1_UI_TagsExample</title></head>

<body><h1>Struts2.2.1_UI_TagsExample</h1><hr/>

<a href="uiTagAction.action">Example of UI Tags.</a>ADS_TO_REPLACE_2

</body>

</html>

2_ uiTags.jsp

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

<html>ADS_TO_REPLACE_3

<head><title>Struts2.2.1_UI_TagsExample</title>

<style type="text/css"> .bh{width: 146;height: 40;}</style></head>

<body><h1>Struts2.2.1_UI_TagsExample</h1><hr/>ADS_TO_REPLACE_4

<s:form action="Information.action">

<s:label name="formName" value="Student Registration Form........"/>

<s:textfield name="name" label="Name"></s:textfield>ADS_TO_REPLACE_5

<s:textarea name="address" label="Address" cssClass="bh"></s:textarea>

<s:password label="Password" name="password"></s:password>

<s:radio list="{'Male','Female'}" name="gender" label="Gender" ></s:radio>ADS_TO_REPLACE_6

<s:select list="course" name="courseName" headerKey="0"

 headerValue="Select Course" label="Course Name"></s:select>

<s:hidden name="message" value="Hello friends....." ></s:hidden>ADS_TO_REPLACE_7

<s:reset></s:reset> <br><s:submit></s:submit>

</s:form>

</body>ADS_TO_REPLACE_8

</html>

3_ UITagAction.java

package roseindia.action;

import java.util.ArrayList;

import java.util.List;ADS_TO_REPLACE_9

import com.opensymphony.xwork2.ActionSupport;

public class UITagAction extends ActionSupport {

private List<String> course;ADS_TO_REPLACE_10

private String courseName;

private String name;

private String address;ADS_TO_REPLACE_11

private String password;

private String gender;

private String message;ADS_TO_REPLACE_12

public String getName() {

return name;

}public void setName(String name) {ADS_TO_REPLACE_13

this.name = name;

}

public String getAddress() {ADS_TO_REPLACE_14

return address;

}

public void setAddress(String address) {ADS_TO_REPLACE_15

this.address = address;

}

public String getPassword() {ADS_TO_REPLACE_16

return password;

}

public void setPassword(String password) {ADS_TO_REPLACE_17

this.password = password;

}

public String getGender() {ADS_TO_REPLACE_18

return gender;

}

public void setGender(String gender) {ADS_TO_REPLACE_19

this.gender = gender;

}

public String getMessage() {ADS_TO_REPLACE_20

return message;

}

public void setMessage(String message) {ADS_TO_REPLACE_21

this.message = message;

}

public String getCourseName() {ADS_TO_REPLACE_22

return courseName;

}

public void setCourseName(String courseName) {ADS_TO_REPLACE_23

this.courseName = courseName;

}

public List<String> getCourse() {ADS_TO_REPLACE_24

return course;

}

public void setCourse(List<String> course) {ADS_TO_REPLACE_25

this.course = course;

}

public UITagAction() {ADS_TO_REPLACE_26

course = new ArrayList<String>();

course.add("MCA");

course.add("MBA");ADS_TO_REPLACE_27

course.add("BCA");

course.add("BBA");

course.add("PGDM");ADS_TO_REPLACE_28

}

public String execute() throws Exception {

return SUCCESS; }ADS_TO_REPLACE_29

}

4_ struts.xml

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" />

<constant name="struts.devMode" value="false" />ADS_TO_REPLACE_30

<package name="bharat" extends="struts-default" namespace="/">

<action name="uiTagAction" class="roseindia.action.UITagAction">

<result >/uitags.jsp</result>ADS_TO_REPLACE_31

</action>

<action name="Information" class="roseindia.action.UITagAction">

<result name="success" >/outputPage.jsp</result>ADS_TO_REPLACE_32

</action>

</package>

</struts>

5_ outputPage.jsp

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

<html>

<head><title>Struts2.2.1_UI_TagsExample</title></head>

<body><h1>Struts2.2.1_UI_TagsExample</h1><hr/>ADS_TO_REPLACE_34

<h4>Student information</h4>

Student Name : <s:property value="name"/><br/>

Student Address : <s:property value="address"/><br/>ADS_TO_REPLACE_35

Student Password : <s:property value="password"/><br/>

Student Gender : <s:property value="gender"/><br/>

Student Course : <s:property value="courseName"/><br/>ADS_TO_REPLACE_36

Hidden Message :<s:property value="message"/>

</body>

</html>

Index.gifADS_TO_REPLACE_37

Uitags.gif

ADS_TO_REPLACE_38

ValueInTags.gif

Value.gifADS_TO_REPLACE_39

Download Select Source Code


Related Tags for Struts2.2.1 UI tag example.:

Advertisements

Ads

Ads

 
Advertisement null

Ads