Reputation: 71
I have a jsp page with list of application names with check boxes to each applications, and there is save button also.
What I need to achieve is that, I need to save these checked value in db and upon loading the jsp page again, I need all the preciously checked application as checked and the rest without checking.
Is there any way to get the stored checked values and check the check boxes while displaying all the applications.
In detail below is my application list with check boxes
☑ Java
☑ Python
☑ C
☐ C++
☐ Rails
☐ ASP
in this list I have selected only first three items and these are stored with my userid
in db as given below
anand -> Java
anand -> Python
anand -> C
Now upon loading this application page again, these three items in db should be checked and others should remain unchecked.
Can any one help?
Upvotes: 1
Views: 2088
Reputation: 1548
To access a db there are tons of tutorials around the web: https://stackoverflow.com/questions/9630275/how-to-get-data-from-a-database-to-a-jsp-page-in-java
When you have your checked values stored in variables (let's say one for each checkbox) you just add this code to your html:
boolean java =//contains the value from the db
String javaChecked="";
if(java==true){
javaChecked="checked='checked'";
}
Then in your html:
<input type="checkbox" id="java" <%= javaChecked %>>
Upvotes: 2