The page below will display 2 checkboxes with the values for user with ID 1.
Movies
Series
Now I have some values in my DB that make sure both of these boxes are checked.
TABLE 'type' ----------- typeID typeName 1 Movies 2 Series TABLE 'user' ------------ userID userName password 1 admin admin 2 test test TABLE 'usersType' usersTypeID userID typeID checked 1 1 1 yes 2 1 2 yes 3 2 1 yes
Below is the code for the preferences.jsp page
<%@page contentType="text/html; charset=iso-8859-1" language="java"%> <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <!DOCTYPE html> <html> <head> <title>Preference Page</title> </head> <body bgcolor="#0099CC"> <div id="navigation"> <ul class="top-level"> <li><a href="success.jsp">Home</a></li> <li><a href="preferences.jsp">Preferences</a></li> <li><a href="recommendations.jsp">Recommendations</a></li> </ul> </div> <div id="wrapper"> <% Connection connection = null; Statement statement = null; ResultSet rs = null; Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); connection = DriverManager.getConnection("jdbc:derby://localhost:1527/recommendation;create=true;user=root;password=root"); statement = connection.createStatement(); %> <form name="frmPreferences" action="updateDatabase.jsp" method="post"> <table> <tr> <td>Do you like to watch movies or series? Or both?</td> </tr> <% String QueryString = "SELECT * FROM APP.TYPE LEFT JOIN APP.userstype ON APP.TYPE.typeID = APP.userstype.typeID AND APP.userstype.userID = " + session.getAttribute("ID"); rs = statement.executeQuery(QueryString); while(rs.next()){ String checked = rs.getString(6); %> <tr> <td><input type="checkbox" name="type"<% if(checked == null){ checked = ""; } if(checked.equals("yes")){ out.print(" checked='checked'"); }else{ out.print("");}%> value="<%=rs.getInt(1)%>" /><%=rs.getString(2)%></td> </tr> <% } rs.close(); %> </table> </form> <% // close all connections statement.close(); connection.close(); %> <br /><br /> <a href="logout.jsp"><b>Logout</b></a> </div> </body> </html>
Now, I want to update these tables via this page. But I don't know how to see if the checkbox is really checked or not.
<%@page contentType="text/html; charset=iso-8859-1" language="java"%> <%@ page import="java.sql.*" %> <%@ page import="java.io.*" %> <% Connection connection = null; PreparedStatement ps = null; Statement statement = null; ResultSet rs = null; Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance(); connection = DriverManager.getConnection("jdbc:derby://localhost:1527/recommendation;create=true;user=root;password=root"); /*statement = connection.createStatement(); String QueryString = " "; rs = statement.executeQuery(QueryString);*/ // get the checkbox values String c[]= request.getParameterValues("type"); // I'M KINDA STUCK HERE... %>