package com.koit.web.beans; public class MemberBean { private String name = ""; private int age = 0; 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; } }
자바 :
MemberBean member = new Member();
jsp :<jsp:useBean class="패키지명.MemberBean" id="member" />
자바 :
member.setName("자바학생");
jsp :<jsp:setProperty name="member" property="name" value="자바학생" />
- name = MemberBean 객체이름
- property = 변수이름
- value = 저장하고자 하는 값
자바 :
member.getName();
jsp :<jsp:getProperty name="member" property="name" />
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <!-- 객체선언 --> <jsp:useBean class="com.koit.web.beans.MemberBean" id="member" /> <jsp:setProperty property="name" name="member" value="김자바"/> <jsp:setProperty property="age" name="member" value="22"/> <table border="1"> <tr> <th>이름</th> <th>나이</th> </tr> <tr> <td><jsp:getProperty property="name" name="member"/></td> <td><jsp:getProperty property="age" name="member"/></td> </tr> </table> </body> </html>