📄 shoppingcart.jsp
字号:
<%--
* @author Rajat Gupta
* @version 1.0
*
* Development Environment : Oracle9i JDeveloper
* Name of the Application : ShoppingCart.jsp
* Creation/Modification History :
*
* Rajat Gupta 22-Jan-2002 Created
*
* Overview of Application :
* This JSP displays two things.
* 1. Products that can be sold by the Retail Shop
* 2. Customers Shopping Cart
* The customer can see all the available products that he can purchase in
* this page. He can add a product to his shopping cart, update the quantity
* in the Shopping Cart or delete a product from the shopping cart.
--%>
<%@ page language="java" %>
<%@ page errorPage="Exception.jsp" %>
<HTML><HEAD>
<script language="JavaScript1.1">
// This function is called when the customer wants to add a product to his
// shopping cart. It submits the form to the ControllerServlet appending the
// appropriate event.
function addToSC(){
if (checkboxesToSell()){
document.ShoppingForm.action = "ControllerServlet?Event=AddProductsToShoppingCart";
document.ShoppingForm.submit();
}else{
alert("Please Select a Product To Add");
}
}
// This function trims the input String. It removes the leading and trailing
// spaces from the String.
function trim(strText) {
// this will get rid of leading spaces
while (strText.substring(0,1) == ' ')
strText = strText.substring(1, strText.length);
// this will get rid of trailing spaces
while (strText.substring(strText.length-1,strText.length) == ' ')
strText = strText.substring(0, strText.length-1);
return strText;
}
// This function validates the quantity ordered.
function validate(quantity){
if (quantity==""){
alert("Quantity cannot be null. Please enter some valid value.");
return 0;
}else if(quantity<= 0){
alert("Quantity cannot be zero or a negative value. Please enter a valid quantity.");
return 0;
}else if (isNaN(quantity)){
alert("Quantity has to be an integer. Please enter a valid quantity.");
return 0;
}
var index = quantity.indexOf(".");
if(index != -1){
alert("Please do not enter '.' in the quantity.");
return 0;
}
return 1;
}
// This function is called when the customer wants to update the quantity of
// a product in his shopping cart. It submits the form to the ControllerServlet
// appending the appropriate event. Before updation, it also checks if any product
// has been added in the shopping cart for updation.
function updateSC(){
if (document.ShoppingForm.EmptyShoppingCart.value == 1){
if (document.ShoppingForm.NoOfProducts.length >1){
for (i=0; i<document.ShoppingForm.NoOfProducts.length; i++){
var flag = validate(trim(document.ShoppingForm.NoOfProducts[i].value));
if(flag == 0){
return false;
}
}
}else{
var flag = validate(trim(document.ShoppingForm.NoOfProducts.value));
if(flag == 0){
return false;
}
}
document.ShoppingForm.action = "ControllerServlet?Event=UpdateProductsFromShoppingCart";
document.ShoppingForm.submit();
return true;
}else{
alert("Please Add a Product to the Shopping Cart");
return false;
}
}
// This function is called before adding a product to the shopping cart.
// It checks if a product has been checked for adding to the shopping cart.
function checkboxesToSell(){
var flag = false;
if (document.ShoppingForm.ProductsToSell.length > 1){
for (i=0; i<document.ShoppingForm.ProductsToSell.length; i++){
if(document.ShoppingForm.ProductsToSell[i].checked){ // Check for true
flag = true;
}
}
}else{
if(document.ShoppingForm.ProductsToSell.checked){ // Check for true
flag = true;
}
}
return flag;
}
// This function is called before deleting a product from the shopping cart.
// It checks if a product has been checked for deletion.
function checkboxesInCart(){
var flag = false;
if (document.ShoppingForm.ProductsInSC.length > 1){
for (i=0; i<document.ShoppingForm.ProductsInSC.length; i++){
if(document.ShoppingForm.ProductsInSC[i].checked){ // Check for true
flag = true;
}
}
}else{
if(document.ShoppingForm.ProductsInSC.checked){ // Check for true
flag = true;
}
}
return flag;
}
// This function is called when the customer wants to delete a product from his
// shopping cart. It submits the form to the ControllerServlet appending the
// appropriate event. Before deletion, it also checks if any product has been
// added in the shopping cart for deletion.
function deleteFromSC(){
if (document.ShoppingForm.EmptyShoppingCart.value == 1){
if (checkboxesInCart()){
document.ShoppingForm.action = "ControllerServlet?Event=DeleteProductsFromShoppingCart";
document.ShoppingForm.submit();
}else{
alert("Please Select a Product To Delete");
}
}else{
alert("Please Add a Product to the Shopping Cart");
}
}
// This function is called when the customer wants to order the products in his
// shopping cart. It submits the form to the ControllerServlet appending the
// appropriate event. Before ordering, it also checks if any product has been
// added in the shopping cart for ordering.
function orderSC(){
if (document.ShoppingForm.EmptyShoppingCart.value == 1){
document.ShoppingForm.action = "ControllerServlet?Event=OrderProductsFromShoppingCart";
document.ShoppingForm.submit();
}else{
alert("Please Add a Product to the Shopping Cart");
}
}
// This function is called when the customer wants to do some operation to all
// the products displayed.
function checkAllProducts(){
if (document.ShoppingForm.SelectAllProducts.checked){ // Check for true
if (document.ShoppingForm.ProductsToSell.length > 1){
for (i=0; i<document.ShoppingForm.ProductsToSell.length; i++){
document.ShoppingForm.ProductsToSell[i].checked = true;
}
}else{
document.ShoppingForm.ProductsToSell.checked = true;
}
}else{
if (document.ShoppingForm.ProductsToSell.length > 1){
for (i=0; i<document.ShoppingForm.ProductsToSell.length; i++){
document.ShoppingForm.ProductsToSell[i].checked = false;
}
}else{
document.ShoppingForm.ProductsToSell.checked = false;
}
}
}
// This function is called when the customer wants to do some operation to all
// the products added to his shopping cart.
function checkAllCart(){
if (document.ShoppingForm.SelectAllCart.checked){ // Check for true
if (document.ShoppingForm.ProductsInSC.length >1){
for (i=0; i<document.ShoppingForm.ProductsInSC.length; i++){
document.ShoppingForm.ProductsInSC[i].checked = true;
}
}else{
document.ShoppingForm.ProductsInSC.checked = true;
}
}else{
if (document.ShoppingForm.ProductsInSC.length >1){
for (i=0; i<document.ShoppingForm.ProductsInSC.length; i++){
document.ShoppingForm.ProductsInSC[i].checked = false;
}
}else{
document.ShoppingForm.ProductsInSC.checked = false;
}
}
}
</script>
<TITLE>Advanced Queuing Sample - Shopping Cart</TITLE>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<link rel="stylesheet" href="stylesheets/styles.css" type="text/css">
<META content="MSHTML 5.00.2314.1000" name=GENERATOR></HEAD>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -