• 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

Remembering the radiobtn/checkbox state between jsp pages

 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do i maintain the state of radio buttons and checkboxs in html forms when i move from one jsp page to another. Thank you for your help. Greatly appreciated..
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can keep their state in the user session, use setAttribute.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Radio buttons and checkboxes that are checked when the form that contains them is submitted will send a name/value pair to the server. Radio buttons and checkboxes that are unchecked will send nothing.

Form parameters are retrieved with the HttpServletRequest.getParameter(String) method; the String argument being the name.
If the name argument doesn't match any form parameters, getParameter will return null.

This means that calling getParameter will return null if the radio button or checkbox is unchecked. If a checkbox or radio button is checked, then calling getParameter with that object's name will return a value.

When generating the HTML for a radio button or checkbox, adding the attribute "checked" will cause that button or checkbox to be checked.

Example:
<input type="checkbox" name="someCheckbox" checked />
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moreover, for checkboxes with the same name, use getParameterValues.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can use the folowing code in the jsp

if(request.getParameterValues()!=null){
for(int i=0;i<request.getParameterValues().length;i++){
<input type=checkbox name="somename" if(request.getParameterValues()!=null)checked>

}
}

syntax and indentatins are not correct.
Hope uu can managae
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Durgaprasad
Welcome to JavaRanch!

We're pleased to have you here with us in the servlets forum, but there
are a few rules that need to be followed, and one is that proper names are
required. Please take a look at the
JavaRanch Naming Policy and
adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

You can change it here
 
reply
    Bookmark Topic Watch Topic
  • New Topic