COMDORI Blog

컴돌이 블로그에 오신것을 환영합니다!

자세히보기

IT/Programming

[JSP] 음료 주문하기 사이트

COMDORI 2020. 4. 9. 16:24
728x90
반응형

2020/03/04 - [IT/Programming Practice] - [JSP] 상품 구매 페이지 만들기

2020/03/24 - [IT/Programming Practice] - [JSP] 입력받아 출력하기 및 while / for 문 출력 하기

2020/03/25 - [IT/Programming Practice] - [JSP] 간단한 로그인과 라디오버튼을 사용하여 계절 출력 하기

2020/03/27 - [IT/Programming Practice] - [JSP] 수강신청 및 주문 사이트 만들기

 

▣ 조건

♪ 커피 종류와 사이즈를 선택하지 않았을 경우 메세지창을 띄웁니다.

♪ 취소 버튼을 클릭하면 취소를 하겠냐는 메세지를 묻습니다.

♪ 자바빈을 사용하여 데이터를 넘기고 출력할 수 있어야 한다.

 setProperty / getProperty를 사용

♪ 주문 번호의 경우 미리 초기화후  getProperty로 값 출력

 

★ 소스를 복사 하려면 소스코드 오른쪽 상단 "Copy"버튼을 클릭하세요.

main.java(자바빈)

package Bean;
import java.sql.Timestamp;
public class main {
private String order_num="2019_0001";
private String coffee;
private String option;
private String size;
private Timestamp time;
public String getOrder_num() {
return order_num;
}
public String getCoffee() {
return coffee;
}
public String getOption() {
return option;
}
public String getSize() {
return size;
}
public Timestamp getTime() {
return time;
}
public void setOrder_num(String order_num)
{
this.order_num = order_num;
}
public void setCoffee(String coffee) {
this.coffee = coffee;
}
public void setOption(String option) {
this.option = option;
}
public void setSize(String size) {
this.size = size;
}
public void setTime(Timestamp time) {
this.time = time;
}
}

main.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!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>Insert title here</title>
</head>
<script type="text/javascript">
function check(){
var frm = document.getElementById("form");
if(frm.coffee.value=="" || frm.coffee.length==0){
alert("커피를 선택해주세요");
return false;
}
else if(frm.size.value=="" || frm.size.length==0){
alert("사이즈를 선택해주세요");
return false;
}
return true;
}
function reset_ok(f) {
var result = confirm("취소하시겠습니까?");
if (!result) {
return false;
}
}
</script>
<body>
<form action="main_result.jsp" id="form" name="form" method="post"
onsubmit="return check()" onreset="return reset_ok(this)">
<h1>음료 주문하기</h1>
<hr>
커피 종류<br> <input type="radio" name="coffee" value="아메리카노">아메리카노
<input type="radio" name="coffee" value="카페라떼">카페라떼 <input
type="radio" name="coffee" value="카페모카">카페모카 <br> 옵션<br>
<input type="radio" name="option" value="hot" checked>hot <input
type="radio" name="option" value="ice">ice <br> 사이즈<br>
<select name="size" id="size">
<option value="">선택해주세요</option>
<option value="Tall">Tall</option>
<option value="Grande">Grande</option>
<option value="Venti">Venti</option>
</select><br>
<br> <input type="submit" value="주문하기"> <input type="reset"
value="취소하기">
</form>
</body>
</html>

main_result.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import="java.sql.Timestamp"%>
<% request.setCharacterEncoding("euc-kr");%>
<!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>주문결과</title>
</head>
<body>
<jsp:useBean id="bean" class="Bean.main">
<jsp:setProperty name="bean" property="*" />
</jsp:useBean>
<jsp:setProperty name="bean" property="time"
value="<%=new Timestamp(System.currentTimeMillis())%>" />
<h1>주문결과</h1>
<hr>
주문번호
<jsp:getProperty name="bean" property="order_num" />
<br> 커피 :
<jsp:getProperty name="bean" property="coffee" />
<br> 옵션 :
<jsp:getProperty name="bean" property="option" />
<br> 사이즈 :
<jsp:getProperty name="bean" property="size" />
<br> 주문시간 :
<jsp:getProperty name="bean" property="time" />
</body>
</html>

◈ 소스코드를 보시고 고칠 부분이나 더 좋은 로직이 있다면 코멘트 달아주세요! 

 

 

컴돌이블로그 | COMDORI BLOG

#JSP #자바스크립트

728x90
반응형