Solved

Accepting radio button input from a form into a servlet

Posted on 1998-08-04
1
470 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

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…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

729 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