Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checkbox

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 13062
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 www.w3.org. A google search for "HTML FORMS TUTORIAL" just found me nearly a million hits.
Bill
 
Gert Cuppens
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
session.setAttribute("land",land);
requestedPage = DETAIL_LAND_PAGE;
} catch (SQLException sqlEx)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic