장바구니
장바구니
문제
로그인화면
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ch06 : login.jsp</title>
</head>
<body>
<div align="center">
<H2>로그인</H2>
<form name="form1" method="POST" action="selProduct(2017305072 전은성).jsp">
<input type="text" name="username"/>
<input type="submit" value="로그인"/>
</form>
</div>
</body>
</html>
과일 선택 화면
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<title>ch06 : selProduct.jsp</title>
</head>
<%
request.setCharacterEncoding("UTF-8"); // euc-kr
session.setAttribute("username",request.getParameter("username"));
%>
<body>
<div align="center">
<H2>상품선택</H2>
<HR>
<%=session.getAttribute("username") %>님 환영합니다!!!!
<HR>
<form name="form1" method="POST" action="add(2017305072 전은성).jsp">
<SELECT name="product">
<option>사과</option>
<option>귤</option>
<option>파인애플</option>
<option>자몽</option>
<option>레몬</option>
</SELECT>
<input type="submit" value="추가"/>
</form>
<a href="checkOut(2017305072 전은성).jsp">계산</a>
</div>
</body>
</html>
과일 추가 화면
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>ch05 : add.jsp</title>
</HEAD>
<body>
<%
request.setCharacterEncoding("UTF-8");
String productname = request.getParameter("product");
ArrayList<String> list = (ArrayList)session.getAttribute("productlist");
if(list == null) {
list = new ArrayList<String>();
session.setAttribute("productlist",list);
}
list.add(productname);
%>
<script>
alert("<%=productname %> 이(가)추가 되었습니다.!!");
history.go(-1);
</script>
</body>
</html>
계산 화면
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>ch06 : checkOut.jsp</title>
</HEAD>
<body>
<div align="center">
<H2>계산</H2>
선택한 상품 목록
<HR>
<%
int apple=0;
int orange=0;
int pineapple=0;
int zamboa=0;
int lemon=0;
int apple2=0;
int orange2=0;
int pineapple2=0;
int zamboa2=0;
int lemon2=0;
ArrayList list = (ArrayList)session.getAttribute("productlist");
if(list == null) {
out.println("선택한 상품이 없습니다.!!!");
}
else {
for(Object productname:list) {
if(productname.equals("사과")){
apple+=1;
}
else if (productname.equals("귤")){
orange+=1;
}
else if (productname.equals("파인애플")){
pineapple+=1;
}
else if (productname.equals("자몽")){
zamboa+=1;
}
else if (productname.equals("레몬")){
lemon+=1;
}
}
for(Object productname:list){
if(productname.equals("사과") && apple2==0){
out.println(productname+" "+apple+"개 "+"(1000 x "+apple+" = "+1000*apple+"원)<br>");
apple2+=1;
}
else if (productname.equals("귤") && orange2==0){
out.println(productname+" "+orange+"개 "+"(2000 x "+orange+" = "+2000*orange+"원)<br>");
orange2+=1;
}
else if (productname.equals("파인애플") && pineapple2==0){
out.println(productname+" "+pineapple+"개 "+"(3000 x "+pineapple+" = "+3000*pineapple+"원)<br>");
pineapple2+=1;
}
else if (productname.equals("자몽") && zamboa2==0){
out.println(productname+" "+zamboa+"개 "+"(4000 x "+zamboa+" = "+4000*zamboa+"원)<br>");
zamboa2+=1;
}
else if (productname.equals("레몬") && lemon2==0){
out.println(productname+" "+lemon+"개 "+"(5000 x "+lemon+" = "+5000*lemon+"원)<br>");
lemon2+=1;
}
}
out.println("<hr>총 개수 "+list.size()+"개<br>");
}
%>
총 주문 금액:
<%
int sum=0;
List<String> list2=(List)session.getAttribute("productlist");
if(list2!=null){
for(String product:list2){
if(product.equals("사과")){
sum+=1000;
}
else if (product.equals("귤")){
sum+=2000;
}
else if (product.equals("파인애플")){
sum+=3000;
}
else if (product.equals("자몽")){
sum+=4000;
}
else if (product.equals("레몬")){
sum+=5000;
}
}
}
out.println(sum+" 원 입니다.");
%>
</div>
</body>
</html>