https://www.youtube.com/playlist?list=PLieE0qnqO2kTyzAlsvxzoulHVISvO8zA9
빈
반복적인 작업을 효율적으로 하기 위해 사용한다. 빈은 Java 언어의 데이터(속성)와 기능(메소드)로 이루어진 클래스이다. jsp 페이지를 만들고, 액션 태그를 이용하여 빈을 사용한다. 그리고 빈의 내부 데이터를 처리한다.
빈 클래스
package com.javalec.ex;
public class Student {
private String name;
private int age;
private int grade;
private int studentNum;
public Student() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
public int getStudentNum() {
return studentNum;
}
public void setStudentNum(int studentNum) {
this.studentNum = studentNum;
}
}
src 폴더 밑에 생성된 패키지 하위에 클래스를 작성한다.
빈 관련 액션 태그
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<jsp:useBean id="student" class="com.javalec.ex.Student" scope="page" />
<!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>
<body>
<jsp:setProperty name="student" property="name" value="홍길동"/>
<jsp:setProperty name="student" property="age" value="13"/>
<jsp:setProperty name="student" property="grade" value="6"/>
<jsp:setProperty name="student" property="studentNum" value="7"/>
이름 : <jsp:getProperty name="student" property="name" /><br />
나이 : <jsp:getProperty name="student" property="age" /><br />
학년 : <jsp:getProperty name="student" property="grade" /><br />
번호 : <jsp:getProperty name="student" property="studentNum" /><br />
</body>
</html>
useBean
<jsp:useBean id="student" class="com.javalec.ex.Student" scope="page" />
id: 임의의 값이고, 빈 객체의 setter, getter 를 접근할 때 참조한다.
class: 클래스 이름을 적는다.
scope: 빈 객체가 유효한 범위이다.
- page: 생성된 페이지 내에서만
- request: 요청된 페이지 내에서만
- session: 웹 브라우저의 생명주기와 동일하게 사용
- application: 웹 어플리케이션 생명 주기와 동일하게 사용
setProperty
<jsp:setProperty name="student" property="name" value="홍길동"/>
getProperty
<jsp:getProperty name="student"
