In this section we will show you how the radio button is used.
RadioButton Example
In this section we will show you how the radio button is used. The following example illustrate you the use of Radio button. Radio button has a feature that it selects only one item at a time. The example given below is describing its features.
RadioButton.html
<html> <head> <title>Radio button example</title> </head> <body> <form method="get" action="RadioButton"> <h2>Select your favorite dish</h2> <p><input type="radio" name="dish" value="Indian"> Indian</input></p> <p><input type="radio" name="dish" value="Continental"> Continental</input></p> <p><input type="radio" name="dish" value="Chinese"> Chinese</input></p> <p><input type="radio" name="dish" value="Italian"> Italian</input></p> <p><input type="radio" name="dish" value="Russian"> Russian</input></p> <input type="submit" value="Submit"></form> </body> </html>
RadioButton.java
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class RadioButton extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { String value; res.setContentType("text/html"); value = req.getParameter("dish"); PrintWriter pw = res.getWriter(); pw.println("<html><body bgcolor=green>"); pw.println("<h3>Your favorite dish is = <font color=yellow>" + value + "</font></h3>"); } }
web.xml
<servlet> <servlet-name>bipul1</servlet-name> <servlet-class>RadioButton</servlet-class> </servlet> <servlet-mapping> <servlet-name>bipul1</servlet-name> <url-pattern>/RadioButton</url-pattern> </servlet-mapping>
Output :
[ 0 ] Comments