jsp에서의 자바빈이란? : java파일로 class파일(객체)를 설계해 놓고, jsp에서 필요에 따라 class를 끌어다 쓰는데 이때 class(객체)를 빈이라고 부른다.

<jsp: ~~> 라는 jsp 액션태그를 이용한다.


















・매회 객체의 클래스 이름을 통해 가져오는게 아니라 useBean을 통해서 클래스와 id값을 연결시키고, 이후부터는 id값을 통해 객체의 프로퍼티에 접근한다.



































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.javalec.ex;
 
public class javaBeanTest {
    private String id;
    private String pw;
    private String bank;
    
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getPw() {
        return pw;
    }
    public void setPw(String pw) {
        this.pw = pw;
    }
    public String getBank() {
        return bank;
    }
    public void setBank(String bank) {
        this.bank = bank;
    }
}
 
cs





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    
<jsp:useBean id="personalInfo" class="com.javalec.ex.javaBeanTest" scope="page"></jsp:useBean>
<!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="personalInfo" property="id" value="da91love"/>
    <jsp:setProperty name="personalInfo" property="pw" value="123123"/>
    <jsp:setProperty name="personalInfo" property="bank" value="kookmin"/>
    
    id : <jsp:getProperty  name="personalInfo" property="id"/><br/>
    pw : <jsp:getProperty  name="personalInfo" property="pw"/><br/>
    bank : <jsp:getProperty  name="personalInfo" property="bank"/><br/>
    
</body>
</html>
cs


+ Recent posts