Login.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>login.jsp</title>
</head>
<body>
<center>
<H2>Log In</H2>
<form name="form1" method="POST" action="selProduct.jsp">
<input type="text" name="username"/>
<input type="submit" value="Log In"/>
</form>
</center>
</body>
</html>
cart.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>selProduct.jsp</title>
</head>
<%
request.setCharacterEncoding("euc-kr");
session.setAttribute("username",request.getParameter("username"));
%>
<body>
<center>
<H2>Select</H2>
<HR>
<%=session.getAttribute("username") %>is logged in.
${username}
<HR>
<form name="form1" method="POST" action="add.jsp">
<SELECT name="product">
<option>Appple</option>
<option>Orange</option>
<option>Pineapple</option>
<option>Grapes</option>
<option>Lemon</option>
</SELECT>
<input type="submit" value="Add"/>
</form>
<a href="checkOut.jsp">Check out</a>
</center>
</body>
</html>
add.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR" import="java.util.ArrayList"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("euc-kr");
// To read parameters
String productname = request.getParameter("product");
// To bring the productlist
ArrayList list = (ArrayList)session.getAttribute("productlist");
if(list == null) {
list = new ArrayList();
}
// Add data in the list
list.add(productname);
session.setAttribute("productlist",list);
%>
<script>
alert("<%=productname %> is added in your cart.");
history.go(-1);
</script>
</body>
</html>
checkOut.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR" import="java.util.ArrayList"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<center>
<H2>Check out</H2>
Your cart
<HR>
<%
ArrayList list = (ArrayList)session.getAttribute("productlist");
// No product is selected
if(list == null) {
out.println("No product is selected");
}
else {
// To print out the list
for(Object productname:list) {
out.println(productname+"<BR>");
}
}
%>
</center>
</body>
</html>
'Codes & Projects' 카테고리의 다른 글
JSP / CSS ) Sign up - JavaBean, Action tags (0) | 2022.08.31 |
---|---|
JSP) Forward /Include action tags - Web page templates (0) | 2022.08.30 |
HTML / Javascript / JSP ) Sign up Form2 (0) | 2022.08.28 |
HTML / Javascript /JSP ) Bulletin Board (0) | 2022.08.28 |
Javascript/ JSP/ HTML ) Log in form (0) | 2022.08.27 |