forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhome.jsp
159 lines (120 loc) · 3.01 KB
/
home.jsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<jsp:useBean id="user" scope="session" class="obs.User" />
<jsp:useBean id="cart" scope="session" class="obs.Cart" />
<%@ page import="java.util.*"%>
<style>
td {font:10pt verdana}
th {font:700 10pt verdana}
h2 {font:700 16pt arial}
a {font:700 10pt verdana;color:darkgreen}
</style>
<%
String act = request.getParameter("act");
if ( act != null )
{
if( act.equals("Finalize Order"))
{
String orderid;
orderid = cart.finalizeOrder( user.getUserid());
if ( orderid == null)
{
out.println("Sorry! Order Cannot be finalized.");
return;
}
else
{
out.println("Order Has Been Finalized. Order id : " + orderid );
out.println("<a href=home.jsp>Continue...</a>");
cart.clearAll();
return;
}
}
if ( act.equals("remove"))
{
cart.removeItem( request.getParameter("isbn"));
}
else
if ( act.equals("Update Cart"))
{
String isbn[] = (String []) request.getParameterValues("isbn");
String qty[] = (String []) request.getParameterValues("qty");
for (int i = 0 ;i < isbn.length ;i ++)
cart.updateQty(isbn[i], Integer.parseInt( qty[i]));
}
else
if ( act.equals("Clear Cart"))
cart.clearAll();
} // end of outer if
%>
<html>
<body bgcolor="beige">
<table border=1 border=1 width=100%>
<tr style="font:700 11pt verdana;background-color:green;color:white">
<td>
Welcome <b><jsp:getProperty name="user" property="uname"/> </b>
</tr>
<tr style="font:10pt verdana">
<td>
<h2>Shopping Cart </h2>
<table width=100%>
<tr>
<td width=70%>
<form action="home.jsp" method="get">
<table border=1 style="background-color:lightgreen" width="100%">
<tr>
<th>Book Title
<th>Price
<th>Quantity
<th>Amount
<th>
</tr>
<%
obs.Item item;
ArrayList items = cart.getItems();
Iterator itr = items.iterator();
int total = 0;
while ( itr.hasNext())
{
item = (obs.Item) itr.next();
total += item.getQty() * item.getPrice();
%>
<tr>
<td>
<input type=hidden value=<%=item.getIsbn()%> name=isbn>
<%= item.getTitle()%>
<td align="right"><%= item.getPrice()%>
<td align="center"><input type=text name=qty size=5 value=<%=item.getQty()%>>
<td align="right"><%=item.getQty() * item.getPrice()%>
<td align="center"><a href=home.jsp?act=remove&isbn=<%=item.getIsbn()%>>Remove</a>
</tr>
<%
}
%>
<tr>
<td colspan=5 style="text-align:center;font:700 12pt verdana;color:navy">
Total Amount : <%=total%>
</tr>
</table>
</td>
<td>
<input type=submit value="Update Cart" name="act">
<p>
<input type=submit value="Clear Cart" name="act">
<p>
<input type=submit value="Finalize Order" name="act">
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td>
[<a href="changeprofile.jsp">Change User Details</a>]
[<a href="browsebooks.jsp">Browse Books</a>]
[<a href="querybooks.jsp">Query Books</a>]
[<a href="ordershistory.jsp">Orders History</a>]
[<a href=logout.jsp> Logout </a>]
</td>
</tr>
</table>
</body>
</html>