1. 속성 영역(page, request, session, application) 에 binding 된 속성 객체를 lookup한다. 만약 가져 오지 못하면 생성하여 그 영역에 binding한다.
2. 태그의 attribute(속성) - id : 자바식별자, binding 시 설정 이름 - class : lookup할 클래스의 이름. fully name으로 설정 - scope : 속성 영역, 값 : page(기본), request, session, application - 예) <jsp:useBean id="mto" class="dto.MemberDTO" scope="request"/>
-> 의미 MemberDTO mto = (MemberDTO)request.getAttribute("mto"); if( mto == null ){ mto = new MemberDTO(); //no-arg 생성자로 생성, 따라서 MemberDTO class에는 반드시 no-arg생성자가 있어야 한다. request.setAttribute("mto",mto); }
[실습] class package : myjsp.dto class : CustomerDTO
package myjsp.dto;
public class CustomerDTO { private String id; private String password; private String name; private String email; private int age; //생성자, setter/getter, toString, equals, hashCode public CustomerDTO() { super(); // TODO Auto-generated constructor stub } public CustomerDTO(String id, String password, String name, String email, int age) { super(); this.id = id; this.password = password; this.name = name; this.email = email; this.age = age; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "CustomerDTO [id=" + id + ", password=" + password + ", name=" + name + ", email=" + email + ", age=" + age + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + age; result = prime * result + ((email == null) ? 0 : email.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((password == null) ? 0 : password.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CustomerDTO other = (CustomerDTO) obj; if (age != other.age) return false; if (email == null) { if (other.email != null) return false; } else if (!email.equals(other.email)) return false; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (password == null) { if (other.password != null) return false; } else if (!password.equals(other.password)) return false; return true; }