All pastes #994381 Raw Edit

Someone

public text v1 · immutable
#994381 ·published 2008-04-23 11:18 UTC
rendered paste body
<%@ page language="java" import="java.util.*, beans.*"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html>

<head>
<body>
<center><h2>Shopping Cart</h2></center>
<!-- response code here -->
<%
	ArrayList cart=(ArrayList) session.getAttribute("itemCart");
	double subtotal =0;
	double total=0;
	double GST=0;
	//DecimalFormat currency = new DecimalFormat("$0.00");
%>
<table>
<tr><td>
	<table align="center" border=1>
	<tr> <th></th>
		<th>Item ID</th>
		<th>Item Description</th>
		<th>Item Quantity</th>
		<th>Item Price</th>
	</tr>
<%
	if (cart!=null)
	{
		//list.size() returns the logical size of the list vector (array)
		for(int c=0;c<cart.size();c++)
		{
			ItemFormBean bean=(ItemFormBean) cart.get(c);
			subtotal = subtotal + (bean.getItemPrice()*bean.getItemQuantity());
			%>			
				<tr>
					<!-- if the user clicks on the link it will delete the client from the cart -->
					<td><a href="deleteItemFromCart.do?itemId=<%=bean.getItemId()%>">Remove</a></td>
					<td><%=bean.getItemId()%></td>
					<td><%=bean.getItemDescription() %></td>
					<td><%=bean.getItemQuantity() %></td>
					<td><%=bean.getItemPrice()%></td>
				</tr>
			<% 
		}
		GST=subtotal*0.05;
		total=subtotal+GST;

	}
%>
	</table>
	</td>
</tr>
<tr><td>
	<table align="right">
		<tr>
			<td>Subtotal</td>
			<td><%=subtotal %></td>
		</tr>
		<tr>
			<td>GST(5%)</td>
			<td><%=GST %></td>
		</tr>
		<tr>
			<td>Total</td>
			<td><%=total %></td>
		</tr>
	</table></td>
</tr>

<tr>
	<td><a href="displayWebStore.do">Add more items to this cart</a></td>
</tr>
<tr>
	<td><a href="emptyCart.do">Empty the Cart</a></td>
</tr>
<tr>
	<td>Already a member? --> <a href="\PaymentInfo.jsp">Checkout Cart</a></td>
</tr>
<tr>
	<td>New member? --> <a href="\Registration.jsp">Register</a></td>
</tr>
<tr>
	<td><a href="\Menu.jsp">Back to the Menu</a></td>
</tr>

</table>
</body>
</html>
---------
package actions;

import java.util.ArrayList;

import javax.servlet.http.*;

import org.apache.struts.action.*;
import managers.*;


 public final class DisplayCartActionServlet extends Action 
 {
	
	public ActionForward execute(	
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) 
	{
		ActionForward nextPage = null;
		HttpSession session= request.getSession();
		
		try 
		{	
			ArrayList cart=(ArrayList) session.getAttribute("itemCart");
			
			if (cart != null)
			{
				nextPage = mapping.findForward("success");
			}
			else
			{
				nextPage = mapping.findForward("failure");
			}
		
		}

		catch(Exception e)
		{
			request.setAttribute("errorMessage","Error: "+e);
			nextPage = mapping.findForward("error");
		}
		
		return (nextPage);
	}
}
----------
package actions;

import java.util.ArrayList;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import beans.*;

public final class DeleteItemFromCartActionServlet extends Action {
	

	public ActionForward execute(	
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) 
	{
		ActionForward nextPage = null;
		int id = Integer.parseInt(request.getParameter("itemId"));
		HttpSession session= request.getSession();
		
		try
		{
			ArrayList cart = (ArrayList) session.getAttribute("itemCart");	
			
			for(int c=0;c<cart.size();c++)
			{
				ItemFormBean bean=(ItemFormBean) cart.get(c);
				if (bean.getItemId()==id)
				{
					cart.remove(c);
				}
			}
			
			session.setAttribute("itemCart", cart);
			nextPage = mapping.findForward("success");
		}
		
		catch(Exception e)
		{
			request.setAttribute("errorMessage","Error: "+e);
			nextPage = mapping.findForward("error");
		}
		return (nextPage);
	}

}
------
package actions;

import java.util.ArrayList;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import beans.*;

public final class EmptyCartActionServlet extends Action {
	

	public ActionForward execute(	
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) 
	{
		ActionForward nextPage = null;
		
		HttpSession session= request.getSession();
		
		try
		{
			ArrayList cart = (ArrayList) session.getAttribute("itemCart");	

			cart.clear();
			
			session.setAttribute("itemCart", cart);
			nextPage = mapping.findForward("success");
		}
		
		catch(Exception e)
		{
			request.setAttribute("errorMessage","Error: "+e);
			nextPage = mapping.findForward("error");
		}
		return (nextPage);
	}

}
---------
<%@ page language="java" import="java.util.*, beans.*"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html>

<head>
<body>
<center><h2>Item List</h2></center>
<!-- response code here -->
<%
	ArrayList list=(ArrayList) request.getAttribute("itemList");
%>

	<table align="center" border=1>
	<tr> <th> </th>
		<th>Item ID</th>
		<th>Item Description</th>
		<th>Item Price</th>
		<th>Item Quantity</th>
	</tr>
<%
	if (list!=null)
	{
		//list.size() returns the logical size of the list vector (array)
		for(int c=0;c<list.size();c++)
		{
			ItemFormBean bean=(ItemFormBean) list.get(c);
			%>			
				<tr>
					<td><a href="loadItem.do?itemId=<%=bean.getItemId()%>">Update Item</a></td>
					
					<td><%=bean.getItemId() %></td>
					<td><%=bean.getItemDescription() %></td>
					<td><%=bean.getItemPrice() %></td>
					<td><%=bean.getItemQuantity()%></td>
				</tr>
			<% 
		}
	}
%>
	</table><br/>

<br/>
<a href="\Menu.jsp">Back to the Menu</a>


</body>
</html>
---------
package actions;

import java.util.ArrayList;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import managers.*;


 public final class DisplayItemsActionServlet extends Action 
 {
	
	public ActionForward execute(	
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) 
	{
		ActionForward nextPage = null;
		
		try 
		{	
			ItemManager manager = new ItemManager();
			ArrayList allItems=manager.get();
			if (allItems != null)
			{
				request.setAttribute("itemList",allItems);
				
				nextPage = mapping.findForward("success");
			}
			else
			{
				nextPage = mapping.findForward("failure");
			}
		
		}

		catch(Exception e)
		{
			request.setAttribute("errorMessage","Error: "+e);
			nextPage = mapping.findForward("error");
		}
		
		return (nextPage);
	}
}
----------
package actions;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import beans.*;
import managers.*;


 public final class EditItemActionServlet extends Action 
 {
	
	public ActionForward execute(	
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) 
	{
		ActionForward nextPage = null;
		
		
		ItemFormBean theForm = (ItemFormBean) form;
		int itemId=theForm.getItemId();
		String itemDescription=theForm.getItemDescription();
		double itemPrice=theForm.getItemPrice();
		int itemQuantity=theForm.getItemQuantity();

		try
		{
			ItemManager manager = new ItemManager();
			
			ItemFormBean bean = new ItemFormBean();
			bean.setItemId(itemId);
			bean.setItemDescription(itemDescription);
			bean.setItemPrice(itemPrice);
			bean.setItemQuantity(itemQuantity);
			
			manager.updateItem(bean);
			
			nextPage = mapping.findForward("success");	
			
		}
		catch(Exception e)
		{
			request.setAttribute("errorMessage","Error: "+e);
			nextPage = mapping.findForward("error");
		}
		return (nextPage);
	}
}
----------
package actions;

import javax.servlet.http.*;
import org.apache.struts.action.*;
import beans.*;
import managers.*;


 public final class LoadItemActionServlet extends Action 
 {
	
	public ActionForward execute(	
			ActionMapping mapping,
			ActionForm form,
			HttpServletRequest request,
			HttpServletResponse response) 
	{
		ActionForward nextPage = null;
		
		int itemId=Integer.parseInt(request.getParameter("itemId"));
		ItemManager manager = new ItemManager();
		
		try
		{
			ItemFormBean bean = manager.getById(itemId);
			ItemFormBean theForm=(ItemFormBean)form;
			
			if (bean != null)
			{
				theForm.setItemId(bean.getItemId());
				theForm.setItemDescription(bean.getItemDescription());
				theForm.setItemPrice(bean.getItemPrice());
				theForm.setItemQuantity(bean.getItemQuantity());
			
				nextPage = mapping.findForward("success");
			}
			
		}

		catch(Exception e)
		{
			request.setAttribute("errorMessage","Error: "+e);
			nextPage = mapping.findForward("error");
		}
		
		return (nextPage);
	}
}
---------
<%@ page language="java" import="beans.*"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>


<html>
<head><title><bean:message key="general.title"/></title></head>
<body>
<bean:message key="edit.title"/>
<br>
<!-- <html:errors/> -->


<table>
<html:form action = "editItem.do" method="post">

	<tr>
		<td align = right><font face = "Verdana"><small>Item Id:</small></font></td>
		<td align = left><html:text property = "itemId"  /> </td>
	</tr>


	<tr>
		<td align = right><font face = "Verdana"><small>Item Description:</small></font></td>
		<td align = left><html:text property = "itemDescription" size = "25" /><html:errors property="itemDescription"/> </td>
	</tr>

	<tr>
		<td align = right><font face = "Verdana"><small>Item Price:</small></font></td>
		<td align = left><html:text property = "itemPrice" size = "25"/><html:errors property="itemPrice"/></td>
	</tr>
		
	<tr>
		<td align = right><font face = "Verdana"><small>Item Quantity:</small></font></td>
		<td align = left><html:text property = "itemQuantity" size = "25"/><html:errors property="itemQuantity"/></td>
	</tr>

	<tr><td colspan="2" align = "center"><html:submit/></td></tr>
		
	</html:form>		
</table>

	<br/>
	<a href="\Menu.jsp">Back to the Menu</a>	
</body>
</html>