Understanding "Music Without Borders"
The main interface for "Music Without Borders" is the JSP page eshop.jsp (see Code Listing 1). You will notice that this page is almost exclusively a dedicated user interface and does not assume any processing tasks--is an ideal JSP solution. Also, note that another JSP page cart.jsp (see Code Listing 2) is eshop.jsp by the instruction <jsp:include page= "cart.jsp" flush= "true"/> included.
Code Listings 1:eshop.jsp
<%@ page session= "true"%>
<title>music without borders</title>
<body bgcolor= "#33CCFF" >
<font face= "Times New roman,times" size= "+3" >
Music without Borders
</font>
<center>
<form name= "Shoppingform"
action= "/examples/servlet/shoppingservlet"
method= "POST" >
<b>CD:</b>
<select name=cd>
<option>yuan | The Guo Brothers | Our | $14.95</option>
<option>drums of Passion | Babatunde Olatunji | Nigeria | $16.95</option>
<option>kaira | Tounami diabate| Mali | $16.95</option>
<option>the Lion is Loose | Eliades Ochoa | Cuba | $13.95</option>
<option>dance the Devil Away | Outback | Australia | $14.95</option>
<option>record of Changes | Samulnori | Korea | $12.95</option>
<option>djelika | Tounami Diabate | Mali | $14.95</option>
<option>rapture | Nusrat Fateh Ali Khan | Pakistan | $12.95</option>
This script mainly takes out the shopping cart from the session. If the cart is empty or has not been created, it is not displayed; Therefore, when the user accesses the application for the first time, the view presented to him is shown in Figure 3:
Figure 3: Music Without Borders, main view
Picture button text: Put in shopping cart
If the shopping cart is not empty, the selected items are taken out of the cart in turn, as shown in the following script fragment:
<%
for (int index=0; index < buylist.size (); index++) {
cd Anorder = (CD) buylist.elementat (index);
%>
Once the variable describing the item is created, it is embedded in the static HTML template using the JSP expression directly. Figure 4 shows the view after the user puts some items into the cart.
Figure 4: Music without Borders, shopping cart view
Text: Music without Borders: Musical no borders; Quantity: quantity; ALBUM: Record; ARTIST: singer; COUNTRY: country; Price: prices; Delete: remove; Checkout: Checkout.
The important point to note here is that the processing of all the actions implemented in eshop.jsp and cart.jsp is controlled by a single servlet――shoppingservlet.java, as shown in Listing 3:
Code Listings 3:shoppingservlet.java
Import java.util.*;
Import java.io.*;
Import javax.servlet.*;
Import javax.servlet.http.*;
Import shopping. CD;
public class Shoppingservlet extends HttpServlet {
public void init (ServletConfig conf) throws Servletexception {
Super.init (conf);
}
public void DoPost (HttpServletRequest req, httpservletresponse Res)
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.