• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Checkbox

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic