Passing checkBox value to another servlet

hey! there,

I am pretty new for java servlet. I am having trouble for passing the name of the checkbox in another servlet.

The situation goes like this.

I have a page where dynamically checkboxes are created based on the number of accounts associated with the user in the database. I have pulled out the information from the database to display in the table where one column is for check box. Now I have to pass the name of the checkbox to the another servlet where I have to ckeck whether the check box value is false or true.

If the number of check box is static, I could have given the specific name which can be passed to the next servlet easily but the I don't know how many checkbox it comes up in the table.

Since I am new to Java, I could not figure out how to name that ckeckbox in the page and pass it to the another servlet page.

Note that the pages are entirely Servlet.

Any help would be heartly, appriciated

[971 byte] By [beginer07a] at [2007-11-26 20:08:17]
# 1

hi beg,

One way to this is

--

Servlet code

for i = 1 to noOFUSers

String x = "<INPUT TYPE=CHECKBOX NAME='user' "+i " >"

put x in screen

-

The HTML generated should post to 2nd servlet

IInd servlet code

Enumeration paramNames = request.getParameterNames();

while(paramNames.hasMoreElements()) {

String paramName = (String)paramNames.nextElement();

if(!paramName.startsWith("user"))// same string as checkbox name

{

continue;

}else{

String paramValue = request.getParameterValue(paramName);

// do u r processing on paramValue

}

}

bipul_k_kuria at 2007-7-9 23:10:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

> hi beg,

> One way to this is

> --

> Servlet code

> for i = 1 to noOFUSers

> String x = "<INPUT TYPE=CHECKBOX NAME='user' "+i "

> >"

> put x in screen

> -

> The HTML generated should post to 2nd servlet

>

> IInd servlet code

>

> Enumeration paramNames =

> request.getParameterNames();

>while(paramNames.hasMoreElements()) {

> String paramName =

> (String)paramNames.nextElement();

> if(!paramName.startsWith("user"))// same string as

> checkbox name

>

> continue;

> }else{

> String paramValue =

> request.getParameterValue(paramName);

> / do u r processing on paramValue

> }

> }

Another way is to use the same name attribute for all of them

<INPUT TYPE=CHECKBOX NAME='user' >

Then, at the second servlet, call

String[] users = request.getParameterValues("name");

and iterate over the string array.

benubacha at 2007-7-9 23:10:54 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...