
Servlet의 Form Beans에 대해 알아보자
학습목표
1. Form benas을 활용할 수 있다. 2. 비즈니스 클래스를 활용하자 |
<코드 1 : buyingmain.html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>문제풀이 : 입력창</title>
</head>
<body>
문
<form action = "result.jsp" method="post">
과일명 : <input type="text" name = "name" value="사과"><br>
정가 : <input type="text" name = "price" value="5000"><br>
할인 : <input type="text" name = "dis" value="1000"><br>
<input type="submit" value="전송"><br>
</body>
</html>
<코드 2 : result.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("UTF-8");
%>
<jsp:useBean id="fruit" class="pack.NameList" />
<jsp:setProperty property="*" name="fruit"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>결과창</title>
</head>
<body>
계산 결과<br>
과일 "<jsp:getProperty property="name" name="fruit"/>"의 :
<jsp:useBean id="bc" class="pack.BusinessClass" />
<jsp:setProperty property="cal" name="bc" value="<%=fruit %>"/>
소비자 실 구매가격은 <jsp:getProperty property="tot" name = "bc" />원
</body>
</html>
<코드 3 : NameList.java>
package pack;
public class NameList {
private String name;
private int price, dis;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public int getDis() {
return dis;
}
public void setDis(int dis) {
this.dis = dis;
}
}
<코드 4 : BusinessClass.java>
package pack;
public class BusinessClass {
private NameList cal;
public void setCal(NameList cal) {
this.cal = cal;
}
public int getTot() {
return cal.getPrice() - cal.getDis();
}
}
결과화면


'[2020]KIC 캠퍼스 복습 > JAVA SCRIPT(5,6,7)' 카테고리의 다른 글
[수업 D-33 ] JSP)Connection pooling,로그인, 게시판 (0) | 2020.08.27 |
---|---|
[수업 D-32 ] Servlet)배운내용 (0) | 2020.08.26 |
[수업 D-31 ] JSP) 지시어, 내장객체 (0) | 2020.08.25 |
[수업 D-30 ] SERVLET) 쿠키, 세션, 쇼핑몰, 방명록 (0) | 2020.08.24 |
[코드리뷰] SERVLET) SERVLET (0) | 2020.08.19 |