Two Laptop Bag*
The moose likes Servlets and the fly likes Remembering the radiobtn/checkbox state between jsp pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Remembering the radiobtn/checkbox state between jsp pages " Watch "Remembering the radiobtn/checkbox state between jsp pages " New topic
Author

Remembering the radiobtn/checkbox state between jsp pages

vanan saravanan
Ranch Hand

Joined: Jun 02, 2006
Posts: 95
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..
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

You can keep their state in the user session, use setAttribute.


[My Blog]
All roads lead to JavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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 />


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Moreover, for checkboxes with the same name, use getParameterValues.
Durgaprasad
Greenhorn

Joined: Oct 02, 2006
Posts: 17
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

Joined: Dec 11, 2004
Posts: 13410

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Remembering the radiobtn/checkbox state between jsp pages
 
Similar Threads
Web-State Pattern
how to implement dynamic choice box in jsp
Web Flow View state identification parameter at client side
communication out.println and request parameter
Problem with items auto change when using IE