⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 manushowproducts.jsp

📁 ORACLE AQ sample 演示的如何出列
💻 JSP
字号:
<%--
  *  @author   Anupama Majety
  *  @version  1.0
  *
  *  Development Environment        : Oracle9i JDeveloper
  *  Name of the Application        : ManuShowProducts.jsp
  *  Creation/Modification History  :
  *
  *     Anupama Majety     22-Jan-2002     Created
  *
  *  Overview of Application        :
  *    This JSP displays all the products the manufacturer holds.
--%>

<%@ page language="java" %>
<%@ page errorPage="Exception.jsp" %>

<HTML><HEAD><TITLE>Advanced Queuing Sample - View All Products</TITLE>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<link rel="stylesheet" href="stylesheets/styles.css" type="text/css">
<script language="JavaScript1.1">

  // This function is called when the manufacturer wants to add a product to his
  // database. It submits the form to the ControllerServlet appending the
  // appropriate event.
  function addProduct(){
    document.ManuShowPrdsForm.action = "ControllerServlet?Event=Add";
    document.ManuShowPrdsForm.submit();
  }
  
  // This function is called when the manufacturer wants to update a product present
  // in his database. Only one product must be seelcted ofr update at a time.
  // If more than one product is selected then a flag is sent and an alert is
  // displayed asking the user to select only one product.
  // It submits the form to the ControllerServlet appending the
  // appropriate event.  
  function updateProduct(){
    // This flag is set if more than one product selected for update.
    var flag=false;
	
  	// Gives number of products selected for updated.
  	var noOfPrdsSelected=0;
	
    // Find the number of products present. If the number of products is
  	// greater than 1 than find the number of them selected.
  	if(document.ManuShowPrdsForm.ProductsToBeChanged.length > 1){
  		var length=document.ManuShowPrdsForm.ProductsToBeChanged.length;
    	for (i=0; i<length; i++){
			
        // Check if the product is selected for updation
        if(document.ManuShowPrdsForm.ProductsToBeChanged[i].checked){
  			 	noOfPrdsSelected++;
			
    			// Check the number of products selected.
      		// As more than one product can't be updated at a time set
        	// the flag value to show an alert.
          if(noOfPrdsSelected>1){
            flag=true;
  					break;
  				}
    	 	}
    	}
  	}else{
    	// only one product is there for updation
      if(document.ManuShowPrdsForm.ProductsToBeChanged.checked){
			 	noOfPrdsSelected++;
		}
	}
	
	// if no product is selected then ask the user to select one product.
	if(noOfPrdsSelected==0){
		alert("Select a product for updation");
		flag=true;
	}else{
		// If more than one product is selected for update then uncheck all the
		// selections and let him select again.
		if(flag){
    	    alert("Only one product can be updated at a time");
			var length=document.ManuShowPrdsForm.ProductsToBeChanged.length;
			for (i=0; i<length; i++){
		      document.ManuShowPrdsForm.ProductsToBeChanged[i].checked=false;
		 	}
		}else{
        	document.ManuShowPrdsForm.action = "ControllerServlet?Event=Update";
		    document.ManuShowPrdsForm.submit();
    	}
	} 
  }
  
  // This function is called when the manufacturer wants to delete products present
  // in his database. It submits the form to the ControllerServlet appending the
  // appropriate event.  
  function deleteProducts(){
  
  	// Gives number of products selected for deletion.
	var noOfPrdsSelected=0;
	if(document.ManuShowPrdsForm.ProductsToBeChanged.length > 1){
		var length=document.ManuShowPrdsForm.ProductsToBeChanged.length;
	
		// This loop is used to check if atleast one product is selected for deletion.
		// so as soon as one product selected is found you break out of the loop.
		for (i=0; i<length; i++){
        	 if(document.ManuShowPrdsForm.ProductsToBeChanged[i].checked){
		 		noOfPrdsSelected++;
				break;
			 }
	    }
	}else{
		// only one product is there for deletion in the database.
		if(document.ManuShowPrdsForm.ProductsToBeChanged.checked){
			 	noOfPrdsSelected++;
		}
	}
	// if no product is selected then ask the user to select one product.
	if(noOfPrdsSelected==0){
		alert("Select a product for Deletion");
	}else{
		// If atleast one product is selected then submit the page.
		document.ManuShowPrdsForm.action = "ControllerServlet?Event=Delete";
    	document.ManuShowPrdsForm.submit();
	}
  }
  
</script>

<META content="MSHTML 5.00.2314.1000" name=GENERATOR></HEAD>
<%@ page import="oracle.otnsamples.AQ.Helper.Product"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.Enumeration"%>

<BODY bgColor=#ffffff  text=#000000>
<form name="ManuShowPrdsForm" method="post">
<!-- Main table -->
 <jsp:include page="include/Top.jsp" />
				  <SPAN class="greeting"> Hi <%= (String)session.getAttribute("Name")%>. You have logged in as a <%= (String)session.getAttribute("User")%> Manufacturer.</SPAN>
			 <jsp:include page="include/Links.jsp" />  			  
  	 <!-- Heading of the page goes here -->
	 
	 <TR><TD class="mainHeading" align="center">Product List</TD></TR>
	 <TR><TD>&nbsp;</TD></TR>
	 <%
	 	String message="";		
		
		// ProductIdArr contains the ID of the product(s) changed. If this or the Action key
		// contains null that means this page is entered after loggin in. If an item is
		// either added or updated or deleted then request object will contain the id of
		// the product and action key will contain the action performed i.e. if the product
		// is either updated or added or deleted.
	 	if(request.getAttribute("ProductIdArr")!=null && request.getAttribute("Action")!=null){
			String[] productIdArr	=	(String[])request.getAttribute("ProductIdArr");
			int length	=	productIdArr.length;
			String listOfIds	=	"";
			
			// This loop helps to construct the message. It constructs the message with
			// the ids seperated by comma if the number of ids is greater than 1.
			for(int i=0;i<length;i++){
			  listOfIds = new StringBuffer().append(listOfIds).append(productIdArr[i]).toString();
			  
			  // If the number of products is less than 1 or the last product is encountered
			  // then comma is not appended in the message.
			  if((length > 1) && (i<(length-1))){
			  	listOfIds = new StringBuffer().append(listOfIds).append(", ").toString();
			  }
			}
			String action=(String)request.getAttribute("Action");
			
			// Depending on the action taken place the message displayed is formed.
			if(action.equals("Add")){
				message=new StringBuffer().append("Product with Id ").append(listOfIds).append(" is added to the database").toString();
			}else if(action.equals("Update")){
				message=new StringBuffer().append("Product with Id ").append(listOfIds).append(" is updated in the database").toString();			
			}else{
				message=new StringBuffer().append("Product(s) with Id ").append(listOfIds).append(" is(are) deleted from the database").toString();			
			}
		}
	 %>
	  <TR><TD class="errorMessage" align="center"><%= message%></TD></TR>
	 <TR>
	    <TD>
			<!-- 5th table starts here working area -->
			<TABLE border=0 cellPadding=0 cellSpacing=0 width=970 >
			  <TBODY> 
			  <TR> 
				<TD valign="top" width="15%" noWrap>&nbsp;</TD>
				<TD vAlign=top width="75%"> 
				<%
				// Get the hash table of products.
				Hashtable productsList=(Hashtable)session.getAttribute("ProductsList");
				if(productsList.size()==0){
				%>
				  <p align="center"><span class="errorMessage" >There are no products to be viewed in the table.</span></p>
				<%
				}else{
				%>
				  <!-- 6th table starts here-->
				  <TABLE border=1 borderColor="#9BCDFF" cellPadding=2 cellSpacing=0 width="100%">
					<TBODY> 
					<TR align="center"> 
	   				  <TD class="data">&nbsp;</TD>
					  <TD class="subHeading" width="4%">S.No</TD>
					  <TD class="subHeading" width="6%">Prd Id</TD>
					  <TD class="subHeading" width="20%">Product Name</TD>
                  	  <TD class="subHeading" width="35%">Product Description</TD>
  					  <TD class="subHeading" width="17%">Category Desc</TD>
					  <TD class="subHeading" width="9%">Price</TD>
					  <TD class="subHeading" width="6%">Quantity on Hand</TD>
					</TR>
			<%
				// Get the enumeration of keys present in the hash table.
				Enumeration enum=productsList.keys();
				int serialNo=0;
				while(enum.hasMoreElements()){
					Object key=enum.nextElement();
					serialNo++;
					
					// Get the details of the product.
					Product product=(Product)productsList.get(key);

			%>
					<TR align="center" height="25"> 
					  <TD class="data">
    	                <input type="checkbox" name="ProductsToBeChanged" value="<%= key%>">					  
					  </TD>
					  <TD class="data"><%= serialNo%></TD>
					  <TD class="data"><%= product.getProductID()%></TD>
					  <TD class="data"><%= product.getProductName()%></TD>
					  <TD class="data"><%= product.getProductDesc()%></TD>
					  <TD class="data"><% if((product.getCategoryDesc()==null)|| product.getCategoryDesc().equals("")){%>
					  						&nbsp;
									   <% }else{%>
									  		<%= product.getCategoryDesc()%>
									   <% }%></TD>
					  <TD class="data"><%= product.getProductPrice()%>$</TD>
					  <TD class="data"><%= product.getQuantityOnHand()%></TD>
					</TR>
				<%
				}
				%>
     			   </TBODY> 
				  </TABLE>
				  
            <!-- 6th table ends here -->
			<%
			}
			%>
            	</TD>
				<TD width="10%">&nbsp;</TD>
			  </TR>
			  <TR><TD colspan=3>&nbsp;</TD></TR>
			  <TR>
	  		   	
            <TD colspan=3 align="center"> <img src="images/add.gif" border=0 width="60" height="32" onMouseUp="addProduct()">
			<%
			 if(productsList.size()!=0){
			%>
              <img src="images/Update.gif" border=0 width="60" height="32" onMouseUp="updateProduct()">	
              <img src="images/delete.gif" border=0 width="60" height="32" onMouseUp="deleteProducts()">	
			  <%
			  }
			  %>
            </TD>
			  </TR>
			  </TBODY> 
			</TABLE>
			<!-- 5th table ends here working area-->
		</TD>
	  </TR>
	  <TR> 
		<TD vAlign=top align=left noWrap>&nbsp;</TD>
	  </TR>
	  <TR> 
		<TD vAlign=top align=left ><image src="images/line.gif" height="3" width="970"></TD>
	  </TR>
	  <TR> 
		
    <TD height=19 vAlign=top align="left"><font face="Arial, Helvetica" size=-2> 
      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &copy; Copyright 2002 Oracle Corporation. 
      All rights reserved.</font> </TD>
	  </TR>
	</TABLE>
	<!-- Main table ends here-->
</form>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -