File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes save checked value in checkbox  to database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "save checked value in checkbox  to database" Watch "save checked value in checkbox  to database" New topic
Author

save checked value in checkbox to database

barbie amr
Greenhorn

Joined: Mar 30, 2004
Posts: 6
Hi
I have problem in saving checkbox values to the database. I have a JSP form which has some 18 checkboxes in it. The form is like providing permissions to particular usergroup. Some group are allowed to use some permissions but say an administrator has chance to work on all modules. Once the check boxes are checked, value 1 should get saved in database either through JSP code or servlets code. We are actually using servlet for database connectivity like adding new record to databse, saving the record etc. How do i trap whether the check boxes are checked or not ? After trapping, how do pass the value 0 or 1 to database based on whether checked or unchecked.
SO now how i go about it ? i.e., saving the checked check box value in databse.
ANd also, when i select a particular group, i need to display all the checkboxes + checked checkboxes for which that group is given permissions
Here is a sample of code which i have written:

Do help me in this issue as early as possible. Eagerly waiting fr reply
thanks in advance
regards
kavitha
Pradheep Thiruvengadam
Greenhorn

Joined: Aug 11, 2003
Posts: 7
try out this,
request.getParametervalues("your checkbox name")
this will give you a string array of check box values that are selected. in your case 1,2,3, .... then do the processing based on the selected values.
Pradheep
barbie amr
Greenhorn

Joined: Mar 30, 2004
Posts: 6
Thanks for ur reply,
I need to tell u one more thing, i am new to both JSP and servlets. so i need to know where i should put the code u told i.e., in JSP page or in servlet or in script. I tried the same code in JSP with <% tags but it didnt work. So do tell me as to where i should put the code
thanks
Welsh Ding
Greenhorn

Joined: Dec 29, 2003
Posts: 14
in UserGrpCreationServlet.java
you can get all checkboxs' value as a array like this:
String[] checkbox = request.getParametervalues("list");


Welsh<br />SCJP 1.4
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

"Kavi" -

Welcome to the JavaRanch! We don't have many rules around the 'Ranch, but we do require your display name to follow the JavaRanch Naming Policy.
You can change it here.

Thanks! and welcome to the JavaRanch!


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
barbie amr
Greenhorn

Joined: Mar 30, 2004
Posts: 6
Hi Welsh,
I am able to trap the checked items in the servlet. Thanks a lot. Now how do i save these into the database. As i have already said i have 5 rows and each row has 3 columns with 1 check box in each column. Suppose the user clicks 1st row 2nd col, 2nd row 3rd adn 4th column, 5th row 1st, 2nd & 3rd columns. In the database also the rows stands for rows and 3 columns stands fr columns (fields). Can anyone advice me as to how to achieve at this. I want to store in the database as 1 fr check boxes clicked and in all other cases as 0.
In the database i want a format like this
------------------------------------------------
GrpName Moduleid aR eR dR
------------------------------------------------
S1 M1 1 0 0
S1 M2 0 1 1
S1 M3 1 1 1
S2 M1 0 0 1
S2 M2 1 0 1
S2 M3 1 0 1
..............
wherein ar, er, dr stands for colums as check boxes. When it is checked, 1 is stored otherwise 0. How od i write insert query fr that?
sorry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: save checked value in checkbox to database