6 Replies - 2577 Views - Last Post: 01 August 2013 - 04:17 AM

#1 Rmarken5  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 29
  • Joined: 08-November 10

Assignment question - deleting table row in servlet.

Posted 13 March 2013 - 11:46 AM

I have two servlet and an object listed below. My assignment is to place an order on one page and see the pending orders on the other. On the pending orders page there is a table with the order information. There is a complete checkbox that when checked, and the update button is clicked, the order will be removed from the table. I am having a problem with figuring this out.

Here is my code.
Order object.

public class Order {
	private String name;
	private String tel;
	private int number;
	private String topping;
	private String size;
	private String instr;
	private boolean done;
	
	
	public Order(String name, String tel, int number, String topping,
			String size, String instr, boolean done) {
		super();
		this.name = name;
		this.tel = tel;
		this.number = number;
		this.topping = topping;
		this.size = size;
		this.instr = instr;
		this.done = done;
	}

	
	
	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getNumber() {
		return number;
	}
	public void setNumber(int number) {
		this.number = number;
	}
	public String getTopping() {
		return topping;
	}
	public void setTopping(String topping) {
		this.topping = topping;
	}
	public String getSize() {
		return size;
	}
	public void setSize(String size) {
		this.size = size;
	}
	public String getInstr() {
		return instr;
	}
	public void setInstr(String instr) {
		this.instr = instr;
	}
	public boolean getDone()
	{
		return done;
		
	}
	public void setDone(boolean done)
	{
		this.done = done;
	}
	
	
	

}


My post order servlet which allows a user to create an order

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* $Id: RequestParamExample.java 1337730 2012-05-12 23:17:21Z kkolinko $
 *
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.xml.internal.ws.util.StringUtils;

import util.HTMLFilter;

/**
 * Example servlet showing request headers
 * 
 * @author James Duncan Davidson <duncan@eng.sun.com>
 */

public class PostOrder extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static int orderNo = 1;
	

	private List<Order> orderList;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);

		orderList = (List<Order>) config.getServletContext().getAttribute(
				"orderlist");

		if (orderList == null) {
			orderList = new ArrayList<Order>();
			config.getServletContext().setAttribute("orderlist", orderList);
		}
	}

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		response.setContentType("text/html");

		PrintWriter out = response.getWriter();
		

		out.println("<!DOCTYPE html>");
		out.println("<html>");
		out.println("<head>");
		out.println("<style>");
		out.println("#content");
		out.println("{");
		out.println("margin:0 auto;");
		out.println("width: 580px;");
		out.println("}");
		out.println("</style>");
		out.println("<title>Jimmy's pizza</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<div id=\"content\">");
		out.println("<center>");
		out.println("<p style=\"font-size:24px\">Jimmy's Pizza</p>");
		out.println("</center>");
		out.println("<style>");
		out.println("#main");
		out.println("{");
		out.println("font-family: Ariel;");
		out.println("font-size: 50%;");
		out.println("background-color: #CC9999; color: black;");
		out.println("border:2px solid black;");
		out.println("}");
		out.println("</style>");
		out.println("<center>");
		out.println("<table id=\"main\">");
		out.println("<tbody>");
		out.println("<tr>");
		out.println("<td>");
		out.println("<form method=\"post\">Name:");
		out.println("<input type=\"text\"name=\"name\" />");
		out.println("</td>");
		out.println("</tr>");
		out.println("<tr>");
		out.println("<td>");
		out.println("Tel:");
		out.println("<input type=\"text\"name=\"tel\" />");
		out.println("</td>");
		out.println("</tr>");
		out.println("<tr>");
		out.println("<td>");
		out.println("Size:");
		out.println("<input type=\"radio\" name=\"size\" value=\"Large\" />Large ");
		out.println("<input type=\"radio\" name=\"size\" value=\"Medium\" />Medium ");
		out.println("<input type=\"radio\" name=\"size\" value=\"Small\" />Small");
		out.println("<br /></td></tr><tr><td>");
		out.println("Toppings:");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Pepperoni\" />Pepperoni");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Sausage\" />Sausage");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Anchovies\" />Anchovies");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Ham\" />Ham");
		out.println("<br />");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Mushrooms\" />Mushrooms");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"GreenPepper\" />Green Pepper");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Onion\" />Onion");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Pinapple\" />Pinapple");
		out.println("</td></tr><tr><td>");
		out.println("Instructions:");
		out.println("<textarea cols=\"50\" rows=\"4\" name=\"comment\"></textarea>");
		out.println("</td></tr></tbody></table></center>");
		out.println("<center>");
		out.println("<button type=\"submit\" name=\"placeorder\">Place Order</button>");
		out.println("<button type=\"submit\" name=\"cancel\">Cancel</button>");
		out.println("</form>");
		out.println("<br />");
		out.println("<p style=\"font-size:45%\">Swtich to:");
		out.println("<a href=\"ListOrders\">Pending Order</a></p></center>");
		out.println("</div></body></html>");

	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		
		String name = request.getParameter("name");
		String tel = request.getParameter("tel");
		String size = request.getParameter("size");
		String[] topping= request.getParameterValues("topping");
		StringBuilder builder = new StringBuilder();

		for (String toppings : topping) {
		    if (builder.length() > 0) {
		        builder.append(" ");
		    }
		    builder.append(toppings);
		}
		String toppings = builder.toString();
		String comment = request.getParameter("comment");

		if (name != null && name.trim().length() > 0) {
			Order order = new Order(name, tel, orderNo++, toppings, size,
					comment, false);
			order.setTopping(toppings);
			orderList.add(order);
		}

		doGet(request, response);
	}

}



Finally my ListOrder class which allows list the pending orders

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* $Id: RequestParamExample.java 1337730 2012-05-12 23:17:21Z kkolinko $
 *
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.HTMLFilter;

/**
 * Example servlet showing request headers
 * 
 * @author James Duncan Davidson <duncan@eng.sun.com>
 */

public class ListOrders extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static int orderNo = 1;

	private List<Order> orderList;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);

		orderList = (List<Order>) config.getServletContext().getAttribute(
				"orderlist");

		if (orderList == null) {
			orderList = new ArrayList<Order>();
			config.getServletContext().setAttribute("order", orderList);
		}
	}

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		response.setContentType("text/html");

		PrintWriter out = response.getWriter();

		out.println("<!DOCTYPE html>");
		out.println("<html>");
		out.println("<head>");
		out.println("<title>" + "List of Orders" + "</title>");
		out.println("<center><p style =\"font-size:24px\">Jimmy's Pizza - Pending Orders</p></center>");
		out.println("</head>");
		out.println("<style>");
		out.println("#content");
		out.println("{");
		out.println("margin:0 auto;");
		out.println("width: 800px;");
		out.println("}");
		out.println("</style>");
		out.println("<div id=\"content\">");
		out.println("<body>");
		out.println("<center>");
		out.println("<style>");
		out.println("#main");
		out.println("{");
		out.println("font-family: Ariel;");
		out.println("font-size: 50%;");
		out.println("background-color: #B0E0E6; color: black;");
		out.println("border:2px solid black;");
		out.println("}");
		out.println("#main2");
		out.println("{");
		out.println("background-color: #B0E0E6; color: black;");
		out.println("border:2px solid black;");
		out.println("padding: 4px");
		out.println("}");
		out.println("</style>");
		out.println("<table border=\"1\" id=\"main2\">");
		out.println("<tr><td>");
		out.println("<table id = \"main\">");
		out.println("<style>");
		out.println("td, th {");
		out.println("border: solid 1px black;");
		out.println("}");
		out.println("</style>");
		out.println("<tr>");
		out.println("<th>cmp</th>");
		out.println("<th>Description</th>");
		out.println("<th>Instructions</th>");
		out.println("<th>For</th>");
		out.println("<th>Phone</th>");
		out.println("</tr>");
		out.println("<form method=\"post\">");
		for (Order order : orderList) {

			out.println("<tr>");
			out.println("<td><input type=\"checkbox\" name=\"remove\" value="
					+ orderNo + "\"\"></td>");
			String pizza = order.getSize() + " " + order.getTopping();
			out.println("<td>" + pizza + "</td>");
			out.println("<td>" + order.getInstr() + "</td>");
			out.println("<td>" + order.getName() + "</td>");
			out.println("<td>" + order.getTel() + "</td>");
			out.println("</tr>");
		}
		out.println("</table></td></tr></table>");

		out.println("<input type=\"submit\" name=\"update\" value=\"update\"></form></td>");
		out.println("<p style=\"font-size:45%\">Swtich to: <a href=\"PostOrder\">Place Order</a></p>");
		out.println("<center></body></div></html>");
		
	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {

	orderList.remove(orderNo);
	orderNo--;

		doGet(request, response);
	}

}



I get an array out of bounds error when I check the box then hit update. Any insight into this problem would be much appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Assignment question - deleting table row in servlet.

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,258
  • Joined: 27-December 08

Re: Assignment question - deleting table row in servlet.

Posted 13 March 2013 - 11:51 AM

Moved to Java EE.

Please post your stack trace.
Was This Post Helpful? 0
  • +
  • -

#3 Rmarken5  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 29
  • Joined: 08-November 10

Re: Assignment question - deleting table row in servlet.

Posted 13 March 2013 - 11:54 AM

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
java.util.ArrayList.rangeCheck(ArrayList.java:604)
java.util.ArrayList.remove(ArrayList.java:445)
ListOrders.doPost(ListOrders.java:138)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

I can go to my tomcat log for full stack trace if you want
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10596
  • View blog
  • Posts: 39,258
  • Joined: 27-December 08

Re: Assignment question - deleting table row in servlet.

Posted 13 March 2013 - 12:03 PM

I'm guessing your error is here orderList.remove(orderNo);. If orderNo = 1, and orderList has 1 element, size == orderNo, so orderNo is out of bounds.
Was This Post Helpful? 0
  • +
  • -

#5 Rmarken5  Icon User is offline

  • New D.I.C Head

Reputation: 3
  • View blog
  • Posts: 29
  • Joined: 08-November 10

Re: Assignment question - deleting table row in servlet.

Posted 13 March 2013 - 12:10 PM

Okay playing around with this application I found if there are two orders and I delete the second one first, it works correctly.

What i need to do is set my checkbox parameter value to list.Size()? Then at the bottom orderList.Remove(orderNo)?

You don't have to reply if you don't know off the top of your head. I'm just asking because I won't have time to check this till later tonight.

This post has been edited by Rmarken5: 13 March 2013 - 12:17 PM

Was This Post Helpful? 0
  • +
  • -

#6 SpAm101  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 54
  • Joined: 28-November 12

Re: Assignment question - deleting table row in servlet.

Posted 15 March 2013 - 09:21 AM

Calling the doGet() method from doPost() is bad practice and goes against how HTTP works.

You should response.sendRedirect instead to create a new GET request, which will call the doGet automatically.
Was This Post Helpful? 0
  • +
  • -

#7 purnaraot  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-August 13

Re: Assignment question - deleting table row in servlet.

Posted 01 August 2013 - 04:17 AM

View PostRmarken5, on 13 March 2013 - 11:46 AM, said:

I have two servlet and an object listed below. My assignment is to place an order on one page and see the pending orders on the other. On the pending orders page there is a table with the order information. There is a complete checkbox that when checked, and the update button is clicked, the order will be removed from the table. I am having a problem with figuring this out.

Here is my code.
Order object.

public class Order {
	private String name;
	private String tel;
	private int number;
	private String topping;
	private String size;
	private String instr;
	private boolean done;
	
	
	public Order(String name, String tel, int number, String topping,
			String size, String instr, boolean done) {
		super();
		this.name = name;
		this.tel = tel;
		this.number = number;
		this.topping = topping;
		this.size = size;
		this.instr = instr;
		this.done = done;
	}

	
	
	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getNumber() {
		return number;
	}
	public void setNumber(int number) {
		this.number = number;
	}
	public String getTopping() {
		return topping;
	}
	public void setTopping(String topping) {
		this.topping = topping;
	}
	public String getSize() {
		return size;
	}
	public void setSize(String size) {
		this.size = size;
	}
	public String getInstr() {
		return instr;
	}
	public void setInstr(String instr) {
		this.instr = instr;
	}
	public boolean getDone()
	{
		return done;
		
	}
	public void setDone(boolean done)
	{
		this.done = done;
	}
	
	
	

}


My post order servlet which allows a user to create an order

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* $Id: RequestParamExample.java 1337730 2012-05-12 23:17:21Z kkolinko $
 *
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sun.xml.internal.ws.util.StringUtils;

import util.HTMLFilter;

/**
 * Example servlet showing request headers
 * 
 * @author James Duncan Davidson <duncan@eng.sun.com>
 */

public class PostOrder extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static int orderNo = 1;
	

	private List<Order> orderList;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);

		orderList = (List<Order>) config.getServletContext().getAttribute(
				"orderlist");

		if (orderList == null) {
			orderList = new ArrayList<Order>();
			config.getServletContext().setAttribute("orderlist", orderList);
		}
	}

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		response.setContentType("text/html");

		PrintWriter out = response.getWriter();
		

		out.println("<!DOCTYPE html>");
		out.println("<html>");
		out.println("<head>");
		out.println("<style>");
		out.println("#content");
		out.println("{");
		out.println("margin:0 auto;");
		out.println("width: 580px;");
		out.println("}");
		out.println("</style>");
		out.println("<title>Jimmy's pizza</title>");
		out.println("</head>");
		out.println("<body>");
		out.println("<div id=\"content\">");
		out.println("<center>");
		out.println("<p style=\"font-size:24px\">Jimmy's Pizza</p>");
		out.println("</center>");
		out.println("<style>");
		out.println("#main");
		out.println("{");
		out.println("font-family: Ariel;");
		out.println("font-size: 50%;");
		out.println("background-color: #CC9999; color: black;");
		out.println("border:2px solid black;");
		out.println("}");
		out.println("</style>");
		out.println("<center>");
		out.println("<table id=\"main\">");
		out.println("<tbody>");
		out.println("<tr>");
		out.println("<td>");
		out.println("<form method=\"post\">Name:");
		out.println("<input type=\"text\"name=\"name\" />");
		out.println("</td>");
		out.println("</tr>");
		out.println("<tr>");
		out.println("<td>");
		out.println("Tel:");
		out.println("<input type=\"text\"name=\"tel\" />");
		out.println("</td>");
		out.println("</tr>");
		out.println("<tr>");
		out.println("<td>");
		out.println("Size:");
		out.println("<input type=\"radio\" name=\"size\" value=\"Large\" />Large ");
		out.println("<input type=\"radio\" name=\"size\" value=\"Medium\" />Medium ");
		out.println("<input type=\"radio\" name=\"size\" value=\"Small\" />Small");
		out.println("<br /></td></tr><tr><td>");
		out.println("Toppings:");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Pepperoni\" />Pepperoni");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Sausage\" />Sausage");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Anchovies\" />Anchovies");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Ham\" />Ham");
		out.println("<br />");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Mushrooms\" />Mushrooms");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"GreenPepper\" />Green Pepper");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Onion\" />Onion");
		out.println("<input type=\"checkbox\" name=\"topping\" value=\"Pinapple\" />Pinapple");
		out.println("</td></tr><tr><td>");
		out.println("Instructions:");
		out.println("<textarea cols=\"50\" rows=\"4\" name=\"comment\"></textarea>");
		out.println("</td></tr></tbody></table></center>");
		out.println("<center>");
		out.println("<button type=\"submit\" name=\"placeorder\">Place Order</button>");
		out.println("<button type=\"submit\" name=\"cancel\">Cancel</button>");
		out.println("</form>");
		out.println("<br />");
		out.println("<p style=\"font-size:45%\">Swtich to:");
		out.println("<a href=\"ListOrders\">Pending Order</a></p></center>");
		out.println("</div></body></html>");

	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		
		String name = request.getParameter("name");
		String tel = request.getParameter("tel");
		String size = request.getParameter("size");
		String[] topping= request.getParameterValues("topping");
		StringBuilder builder = new StringBuilder();

		for (String toppings : topping) {
		    if (builder.length() > 0) {
		        builder.append(" ");
		    }
		    builder.append(toppings);
		}
		String toppings = builder.toString();
		String comment = request.getParameter("comment");

		if (name != null && name.trim().length() > 0) {
			Order order = new Order(name, tel, orderNo++, toppings, size,
					comment, false);
			order.setTopping(toppings);
			orderList.add(order);
		}

		doGet(request, response);
	}

}



Finally my ListOrder class which allows list the pending orders

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/* $Id: RequestParamExample.java 1337730 2012-05-12 23:17:21Z kkolinko $
 *
 */

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.HTMLFilter;

/**
 * Example servlet showing request headers
 * 
 * @author James Duncan Davidson <duncan@eng.sun.com>
 */

public class ListOrders extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static int orderNo = 1;

	private List<Order> orderList;

	public void init(ServletConfig config) throws ServletException {
		super.init(config);

		orderList = (List<Order>) config.getServletContext().getAttribute(
				"orderlist");

		if (orderList == null) {
			orderList = new ArrayList<Order>();
			config.getServletContext().setAttribute("order", orderList);
		}
	}

	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		response.setContentType("text/html");

		PrintWriter out = response.getWriter();

		out.println("<!DOCTYPE html>");
		out.println("<html>");
		out.println("<head>");
		out.println("<title>" + "List of Orders" + "</title>");
		out.println("<center><p style =\"font-size:24px\">Jimmy's Pizza - Pending Orders</p></center>");
		out.println("</head>");
		out.println("<style>");
		out.println("#content");
		out.println("{");
		out.println("margin:0 auto;");
		out.println("width: 800px;");
		out.println("}");
		out.println("</style>");
		out.println("<div id=\"content\">");
		out.println("<body>");
		out.println("<center>");
		out.println("<style>");
		out.println("#main");
		out.println("{");
		out.println("font-family: Ariel;");
		out.println("font-size: 50%;");
		out.println("background-color: #B0E0E6; color: black;");
		out.println("border:2px solid black;");
		out.println("}");
		out.println("#main2");
		out.println("{");
		out.println("background-color: #B0E0E6; color: black;");
		out.println("border:2px solid black;");
		out.println("padding: 4px");
		out.println("}");
		out.println("</style>");
		out.println("<table border=\"1\" id=\"main2\">");
		out.println("<tr><td>");
		out.println("<table id = \"main\">");
		out.println("<style>");
		out.println("td, th {");
		out.println("border: solid 1px black;");
		out.println("}");
		out.println("</style>");
		out.println("<tr>");
		out.println("<th>cmp</th>");
		out.println("<th>Description</th>");
		out.println("<th>Instructions</th>");
		out.println("<th>For</th>");
		out.println("<th>Phone</th>");
		out.println("</tr>");
		out.println("<form method=\"post\">");
		for (Order order : orderList) {

			out.println("<tr>");
			out.println("<td><input type=\"checkbox\" name=\"remove\" value="
					+ orderNo + "\"\"></td>");
			String pizza = order.getSize() + " " + order.getTopping();
			out.println("<td>" + pizza + "</td>");
			out.println("<td>" + order.getInstr() + "</td>");
			out.println("<td>" + order.getName() + "</td>");
			out.println("<td>" + order.getTel() + "</td>");
			out.println("</tr>");
		}
		out.println("</table></td></tr></table>");

		out.println("<input type=\"submit\" name=\"update\" value=\"update\"></form></td>");
		out.println("<p style=\"font-size:45%\">Swtich to: <a href=\"PostOrder\">Place Order</a></p>");
		out.println("<center></body></div></html>");
		
	}

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {

//	orderList.remove(orderNo);
//	orderNo--;
 if (orderNo >= 0) {
			orderList.remove(orderNo);
		}
		doGet(request, response);
	}

}



I get an array out of bounds error when I check the box then hit update. Any insight into this problem would be much appreciated.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1