In Struts 2 , you can use the <s:radio> tag to create a HTML radio button. The funny stuff is there are many ways to populate the data into the radio button, via List, OGNL or Object. Check the below example to know how.

Struts 2 <s:radio> example

Example to show the use of List, OGNL and Object to populate data to a radio button that’s created via Struts 2 <s:radio> tag.

1. Action

Action class to create list of the genders and languages values for radio button.

package com.mkyong.common.action;

import java.util.ArrayList;
import java.util.List;

import com.mkyong.common.model.Language;
import com.opensymphony.xwork2.ActionSupport;

public class RadioButtonAction extends ActionSupport{

	private List<String> genders;
	private List<Language> languages ;
	private String yourGender;
	private String yourAnswer;
	private String yourLanguage;
	private static final String MALE = "male";
	private static final String FEMALE = "female";
	private static final String UNKNOWN = "unknown";
	public RadioButtonAction(){
		genders = new ArrayList<String>();
		languages = new ArrayList<Language>();
		languages.add( new Language("EN", "English") );
		languages.add( new Language("FR", "France") );
		languages.add( new Language("CN_ZH", "Chinese") );
		languages.add( new Language("DE", "German") );
	//return default gender value
	public String getDefaultGenderValue(){
		return UNKNOWN;

	//return default language value
	public String getDefaultLanguageValue(){
		return "CN_ZH";
	public String execute() {
		return SUCCESS;
	public String display() {
		return NONE;
	//getter ad setter methods

package com.mkyong.common.model;

public class Language{

	private String languageCode;
	private String languageDisplay;
	//getter and setter methods
	public Language(String languageCode, String languageDisplay) {
		this.languageCode = languageCode;
		this.languageDisplay = languageDisplay;

2. Result page

Result page to use Struts 2 “s:radio” to create three radio buttons via List, OGNL and object.


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

<h1>Struts 2 radio button example</h1>

<s:form action="resultAction" namespace="/">

  <s:radio label="Gender" name="yourGender" list="genders" value="defaultGenderValue" />
  <s:radio label="Gender" name="yourLanguage" list="languages" 
      listKey="languageCode" listValue="languageDisplay" value="defaultLanguageValue" />
  <s:radio label="Answer" name="yourAnswer" list="#{'1':'Yes','2':'No'}" value="2" />

<s:submit value="submit" name="submit" />



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

<h1>Struts 2 radio button example</h1>

  Your Selected Gender : <s:property value="yourGender"/>
  Your Selected Language : <s:property value="yourLanguage"/>
  Your Selected Answer : <s:property value="yourAnswer"/>


3. struts.xml

Link all together ~

<?xml version="1.0" encoding="UTF-8" ?>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

<constant name="struts.devMode" value="true" />
  <package name="" namespace="/" extends="struts-default">
    <action name="radioButtonAction" 
         class="com.mkyong.common.action.RadioButtonAction" method="display">
		<result name="none">pages/radiobutton.jsp</result>
    <action name="resultAction" class="com.mkyong.common.action.RadioButtonAction">
		<result name="success">pages/result.jsp</result>

5. Demo


Struts2 radio button screen


Struts2 radio button screen
To understand how to preselect a value, read this article – preselect a radio button value in Struts 2


  3. How to preselect a radio button value in Struts 2