Solved

Accepting radio button input from a form into a servlet

Posted on 1998-08-04
1
465 Views
Last Modified: 2013-11-24
Please give me the code to get a value from a radio button when a form is posted to a servlet.
In my servlet I have:

cases=req.getParameter("case");

case is the radio button and cases is a boolean to store the value of it, true or false. This doesn't work as getParameter is looking for a String return from case not a boolean. What does a radio button return and how do I code for it.

Thanks
Mel
0
Comment
Question by:help_me
1 Comment
 
LVL 2

Accepted Solution

by:
shchuka earned 50 total points
ID: 1230864
When you have a radio buttons on your HTML form, you usually have several radio buttons with the same name - that's how the browser knows that these buttons form a group and lets you select only one of them.  Thus, in HTML you'll have:

<input type=radio name="case" value="option1"> Option 1
<input type=radio name="case" value="option2"> Option 2
.

In your servlet, you'll have

String cases = req.getParameter("case");

And your cases variable will be set to the value you specified in the button (the one selected).  Thus, if of the two buttons above you selected the first one, cases will contain "option1", and if the second one selected, cases will have "option2"
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now