?
Solved

Accepting radio button input from a form into a servlet

Posted on 1998-08-04
1
Medium Priority
?
471 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 150 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

770 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