Struts2.2.1 radio Tag Example
Posted on: January 18, 2011 at 12:00 AM
The radio tag is a UI tag that render a radio button input field.

Struts2.2.1 radio Tag Example

The radio tag is a UI tag that render a radio button input field.

The following Example will shows how to implement the radio tag in the Struts2.2.1 --

First we create a JSP file named RadioTag.jsp as follows.ADS_TO_REPLACE_1

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


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"ADS_TO_REPLACE_2


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



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Example radio Tag</title>ADS_TO_REPLACE_4



<s:form action="ResultRadioTag.action">ADS_TO_REPLACE_5

<h2>Fill Your Details.</h2>

<s:textfield name="username" key="Name"></s:textfield>

<s:radio list="#{'Male':'Male','Female':'Female'}" value="Gender"ADS_TO_REPLACE_6


<s:radio list="#{'Single':'Single','Married':'Married'}" value="Status"




'Self Employed':'Self Employed'}"ADS_TO_REPLACE_8

value="Employement" name="list3"></s:radio>





The Struts mapping file Struts.xml is as follows-

<?xml version="1.0" encoding="UTF-8"?>ADS_TO_REPLACE_10


"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"



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

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

<constant name="struts.custom.i18n.resources" value="ApplicationResources" />

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

<action name="RadioTag" class="roseindia.RadioTag" method="display">ADS_TO_REPLACE_13

<result name="none">/RadioTag.jsp</result>


<action name="ResultRadioTag" class="roseindia.RadioTag">ADS_TO_REPLACE_14

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




Here is the result.jsp

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


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


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



<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">ADS_TO_REPLACE_18

<title>Example radio Tag</title>



<h1><s:property value="username"/> Your detail is here</h1>

Welcome Dear friend,<s:property value="username"/><br>

Your Gender is : <s:property value="list1"/><br>ADS_TO_REPLACE_20

Your Status is :<s:property value="list2"/><br>

Your are a <s:property value="list3"/> Person.



The action class is as follows.

package roseindia;

import com.opensymphony.xwork2.ActionSupport;ADS_TO_REPLACE_22

public class RadioTag extends ActionSupport {

private String username;

private String list1;ADS_TO_REPLACE_23

private String list2;

private String list3;

public String execute() throws Exception {ADS_TO_REPLACE_24

return SUCCESS;


public String getList1() {ADS_TO_REPLACE_25

return list1;


public void setList1(String list1) {ADS_TO_REPLACE_26

this.list1 = list1;


public String getList2() {ADS_TO_REPLACE_27

return list2;


public void setList2(String list2) {ADS_TO_REPLACE_28

this.list2 = list2;


public String getList3() {ADS_TO_REPLACE_29

return list3;


public void setList3(String list3) {ADS_TO_REPLACE_30

this.list3 = list3;


public String getUsername() {ADS_TO_REPLACE_31

return username;


public void setUsername(String username) {ADS_TO_REPLACE_32

this.username = username;


public String display() {ADS_TO_REPLACE_33

return NONE;



This Program produces output on the basis of the Radio Tag evaluation, This  give the output as-ADS_TO_REPLACE_34




Download Select Source Code

Related Tags for Struts2.2.1 radio Tag Example:



Advertisement null