Radio Button in JSP Page Example

Hey guys in this article, you will learn about creating the radio button and reading the radio button value in JSP with full code example.

Read More:


To create a radio button in HTML we will use <input type="radio"> tag. It contains name attribute.

<input type="radio" name="gender" value="Male" />Male

To read the radio button value in JSP, we will use the request object

<%= request.getParameter("radioButtonName") %>

getParameter() takes the name of the radio button. Another shortcut method to read radio button value is using param object


Using param object we can read the radio button value.

Complete Example

Follow the below steps to understand the complete example

Create a Project

You can check the following post to create a new Dynamic Web Project

Create a HTML form

Create EmployeeForm.html file under WebContent and add the following content

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
		<title>Employee Form</title>

		<form action="employee-details.jsp">
			First Name:
			<input type = "text" name = "firstName" />
			Last Name:
			<input type = "text" name = "lastName" />
			Select country:
			<select name = "country">
			Select Gender:
			<input type="radio" name="gender" value="Male" />Male
			<input type="radio" name="gender" value="Female" />Female
			<button type="submit">Submit</button>


Create a JSP file

Create employee-details.jsp file under WebContent and add the following content

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<!DOCTYPE html>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
	<h1>Employee details</h1>
	<p>First Name: ${param.firstName}</p>
	<p>Last Name: ${param.lastName}</p>
	<p>Country: ${}</p>
	<p>Gender: ${param.gender}</p>

Run the file

Right click on the File, choose Run As, choose Run on Server. It will open in a default web browser, you will see the following content


That’s it for this post, if you like this post, please share this post with your friends and collogues and also share this on your social media profiles.

About the author

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

View all posts

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *