Solved

Accepting radio button input from a form into a servlet

Posted on 1998-08-04
1
466 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
groupSum6 challenge 6 85
servlet  URL Rewriting 1 36
windows explorer path to command prompt 5 42
login form jsp example 2 24
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

816 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

9 Experts available now in Live!

Get 1:1 Help Now