forgive me , but im not sure if this is the right forum for servlet help. im getting to that desperate state with my project , my teacher is no help at all and im hoping to get some help here.
im trying to finish this servlet that adds a new course to my courses display. im using a check box so the user can pick what the prerequisite are for the new course they want to add. so if they check cs201 , it will add cs201 as a prerequisite for that new course.
for some reason my checkbox will only add the first checkbox that is clicked. like if i add a subject , and click the check boxs for cs203 , cs202, and cs201. it will only grab cs201 and add it to my course display. it wont grab all 3. how can i grab the other info thats checked?
package cs320Homework1.servlet; import java.io.IOException; import java.io.PrintWriter; import java.util.List; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import cs320Homework1.servlet.Courses; @WebServlet("/AddCourse") public class AddCourse extends HttpServlet { private static final long serialVersionUID = 1L; public AddCourse() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("<html><head><title>AddCourse</title></head><body>"); out.println("<form action='AddCourse' method ='post'/> "); out.println("Code: <input type='text' name='code'/> <br /> "); out.println("Title: <input type='text' name='title' /> <br />"); out.println("Prerequisite(s): <input type='checkbox' name='prerequisites value='CS120' >CS 120<br>"); out.println("Prerequisite(s): <input type='checkbox' name='prerequisites value='CS122' >CS 122<br>"); out.println("Prerequisite(s): <input type='checkbox' name='prerequisites value='CS201' >CS 201<br>"); out.println("Prerequisite(s): <input type='checkbox' name='prerequisites value='CS202' >CS 202<br>"); out.println("Prerequisite(s): <input type='checkbox' name='prerequisites value='CS203' >CS 203<br>"); out.println("Prerequisite(s): <input type='checkbox' name='prerequisites value='CS320' >CS 320<br>"); out.println("<input type='submit' name='add' value='Add' /> <br />"); out.println("</form>"); out.println("</body></html>"); } @SuppressWarnings("unchecked") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String code = request.getParameter("code"); String title = request.getParameter("title"); String prerequisites= request.getParameter("prerequisites"); List<Courses> entries = (List<Courses>) getServletContext() .getAttribute("entries"); entries.add(new Courses (code,title, prerequisites)); response.sendRedirect( "Courses" ); } }