File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Checkbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Checkbox" Watch "Checkbox" New topic


Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
In a servlet, how do I get the list of checkbox values the user has entered in an HTML form?
For example- for a textbox it would be-
name = request.getParameter("name");

In a servlet, how do I get the value of a radio button from a group of radio buttons, the user has entered in an HTML form?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13035
You need to get a good reference for HTML and the CGI conventions for Forms. Personally, I like the "Hip Pocket Guide to HTML 4" if you can find it. You can also download the full specs from A google search for "HTML FORMS TUTORIAL" just found me nearly a million hits.
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
I'm using radio buttons on a JSP which displays all the countries I have in my database. Each row contains a radio button and this radio button has the value of the ID of the country record.
The JSP contains therefore :
<td><input type="radio" name="landSelectie" value="<%=land.getID()%>"></td>
With the submit button I hand the control over to the servlet. The servlet knows the name of the form and so knows which function it should call. This function then controlls the value of the selected radio button and therefore knows the ID of the country record. This record is then looked up end displayed in de detail Form of another JSP.
The controlling of the value of the radio button is as follows :
int landID = DaUtil.vanStringNaarInt(request.getParameter("landSelectie"));
System.out.println("voor landdao - opzoeken van land ID " + landID);
LandDao landDao = new LandDao();
try {
Land land = landDao.zoekLandOpID(landID);
HttpSession session = request.getSession(false);
System.out.println("voor noteren land in sessie");
requestedPage = DETAIL_LAND_PAGE;
} catch (SQLException sqlEx)
I agree. Here's the link:
subject: Checkbox
It's not a secret anymore!