Solved

Accepting radio button input from a form into a servlet

Posted on 1998-08-04
1
462 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
scoreUp challenge 14 48
json example 39 110
groovy example issue 10 65
Error with Java/Cache JDBC Classpath 2 19
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

743 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

10 Experts available now in Live!

Get 1:1 Help Now