- ProductInfo.java
- BookInfo.java
- ClothingInfo.java
ProductInfo.java
package mall;
abstract public class ProductInfo {
private String code;
private String name;
private int price;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
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;
}
}
BookInfo.java
package mall;
public class BookInfo extends ProductInfo {
private short page;
private String writer;
public short getPage() {
return page;
}
public void setPage(short page) {
this.page = page;
}
public String getWriter() {
return writer;
}
public void setWriter(String writer) {
this.writer = writer;
}
}
ClothingInfo.java
package mall;
public class ClothingInfo extends ProductInfo {
private char size;
private String color;
public void setSize(char size){
this.size = size;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public char getSize() {
return size;
}
}
3종류의 jsp 페이지 생성
- ProductInfo.jsp
- BookInfo.jsp
- ClothingInfo.jsp
ProductInfo.jsp : 부모
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- 사용하는 자바빈의 부모가 abstract(추상class)일 경우 type="" -->
<!-- 사용하는 자바빈의 부모가 일반class일 경우 class="" -->
<jsp:useBean id="pinfo" type="mall.ProductInfo" scope="request" />
코드 : <jsp:getProperty name="pinfo" property="code" /><br/>
제품명 : <jsp:getProperty name="pinfo" property="name" /><br/>
가격 : <jsp:getProperty name="pinfo" property="price" /><br/>
↓
BookInfo.jsp : 실행
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<jsp:useBean id="pinfo" class="mall.BookInfo" scope="request">
<jsp:setProperty name="pinfo" property="code" value="50001" />
<jsp:setProperty name="pinfo" property="name" value="의뢰인" />
<jsp:setProperty name="pinfo" property="price" value="9000" />
<jsp:setProperty name="pinfo" property="writer" value="존 그리샴" />
<jsp:setProperty name="pinfo" property="page" value="704" />
</jsp:useBean>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>표준액션 : useBean -다형성-</title>
</head>
<body>
책정보가 저장되었습니다 <br><br>
===============================<br>
<h3>제품 정보</h3>
<jsp:include page="ProductInfo.jsp" />
</body>
</html>
ClothingInfo.jsp : 실행
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<jsp:useBean id="pinfo" class="mall.ClothingInfo" scope="request">
<jsp:setProperty name="pinfo" property="code" value="70002" />
<jsp:setProperty name="pinfo" property="name" value="목폴라 티" />
<jsp:setProperty name="pinfo" property="price" value="10000" />
<jsp:setProperty name="pinfo" property="size" value="M" />
<jsp:setProperty name="pinfo" property="color" value="베이지" />
</jsp:useBean>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>표준액션 : useBean -다형성-</title>
</head>
<body>
의류정보가 저장되었습니다 <br><br>
===============================<br>
<h3>제품 정보</h3>
<jsp:include page="ProductInfo.jsp" />
</body>
</html>
'JAVA > JSP & Servlet' 카테고리의 다른 글
표준 액션(standard action) : Applet 불러오기 (0) | 2013.03.22 |
---|---|
표준 액션(standard action) : 스크립팅 요소를 대신하는 표준액션 (0) | 2013.03.22 |
표준 액션(standard action) : useBean (property="*") (0) | 2013.03.22 |
표준 액션(standard action) : useBean (param) (0) | 2013.03.22 |
표준 액션(standard action) : useBean (scope) (0) | 2013.03.22 |