How to store checkbox value into database?
I have a table which each row have a few checkbox and n开发者_Go百科ow i would like to do it if i have click on that checkbox it will update it inside the database. How can i code it using jsp?
First define a form in JSP which submits to a servlet.
<form action="servleturl" method="post>
Then place a checkbox in there with a name and value.
<input type="checkbox" name="foo" value="bar" />
Then create a servlet which listens on /servleturl
and gets the parameter in doPost()
method.
String foo = request.getParameter("foo");
It'll contain bar
or null
depending on checked state. Then you can do your DB thing.
fooDAO.save(someID, foo);
If that's also a problem already, then you need to learn JDBC and DAO. This is however unrelated to JSP/Servlets. Start with the JDBC tutorial.
精彩评论