Question
Javascript: How to make the previous button show the previously selected checkboxes. So whenever I push the previous button it simply clears all the boxes
Javascript: How to make the previous button show the previously selected checkboxes. So whenever I push the previous button it simply clears all the boxes and I don't know how to make it do what I want. This should be enough, but if you need more of my code just put your email in your answer and I can send all of it.
reservationList.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@page import="java.util.ArrayList"%> <%@page import="java.util.Date"%> <%@page import="java.text.SimpleDateFormat"%> <%@page import = "model.*" %>
CE6
Travel Items
<% session = request.getSession(); ArrayList reservation = (ArrayList)session.getAttribute("reservation"); ArrayList travelItem = (ArrayList)session.getAttribute("travelItem"); ArrayList checkList = new ArrayList(); for (int i = 0; i < reservation.size(); i++){ checkList.add(i, (String)session.getAttribute("select"+i)); } SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd"); for (int i = 0; i < reservation.size(); i++) { %> <% } %>
Item Code | Type | Description | Travelers | Start Date | End Date | Select |
---|---|---|---|---|---|---|
<%=reservation.get(i).getItemCode() %> | <%=travelItem.get(i).getItemType() %> | <%=travelItem.get(i).getItemDesc() %> | <%=reservation.get(i).getTravelers() %> | <%=df.format(reservation.get(i).getStartDate()) %> | <%=df.format(reservation.get(i).getEndDate()) %> |
CE6Servlet.java
package controller;
import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import model.Reservations; import model.TravelItems;
/** * * @author wmschane */ public class CE6Servlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Create sample reservation data. In later exercises, this will be stored in a database // and accessed with SQL statements. SimpleDateFormat df = new SimpleDateFormat ("yyyy-MM-dd"); Date d1 = null, d2 = null, d3 = null, d4 = null, d5 = null; String url = null; HttpSession session = request.getSession(); String action = request.getParameter("action"); ArrayList reservation = new ArrayList(); // Reservations try { d1 = df.parse("2017-02-20"); d2 = df.parse("2017-02-25"); d3 = df.parse("2017-02-22"); } catch (ParseException ex) { Logger.getLogger(CE6Servlet.class.getName()).log(Level.SEVERE, null, ex); } // Assume arrays are parallel. Travel item "0" goes with reservation "0"
reservation.add(new Reservations("R433","I239",2,d1,d2)); reservation.add(new Reservations("R123","I133",2,d1,d2)); reservation.add(new Reservations("R223","I425",2,d3,d3));
ArrayList travelItem = new ArrayList(); travelItem.add(new TravelItems("I239","Hotel", "Disney World Orlando")); travelItem.add(new TravelItems("I133","Hotel", "Hilton Orlando Hotel")); travelItem.add(new TravelItems("I425","Restaurant", "The Crab Shack")); if (action.equals("reservations")) { session.setAttribute("reservation", reservation); session.setAttribute("travelItem", travelItem); url = "/reservationList.jsp"; } else if (action.equals("selections")) { String check; for (int i = 0; i < reservation.size(); i++){ check = request.getParameter("select"+i); session.setAttribute("select"+i, check); } url = "/reservationSelections.jsp"; } else if (action.equals("previous")) { url = "/reservationList.jsp"; } getServletContext().getRequestDispatcher(url) .forward(request, response); }
// /** * Handles the HTTP GET method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
/** * Handles the HTTP POST method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); }
/** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }//
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started