본문 바로가기

JAVA/JSP & Servlet

표준 액션(standard action) : useBean

 

 

 

 

 

PersonalInfo.java

package mall;

 

public class PersonalInfo {

 

        private String name;

        private char gender;

        private int age;

       

       

        public String getName() {

               return name;

        }

        public void setName(String name) {

               this.name = name;

        }

        public char getgender() {

               return gender;

        }

        public void setgender(char gender) {

               this.gender = gender;

        }

        public int getAge() {

               return age;

        }

        public void setAge(int age) {

               this.age = age;

        }

       

}

 

 

 

 

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

 

<!-- HTML 밖에 써주면 보기 편함 :) -->

<jsp:useBean id="pinfo" class="mall.PersonalInfo" />

<jsp:setProperty name="pinfo" property="name" value="이종표" />

<jsp:setProperty name="pinfo" property="gender" value="" />

<jsp:setProperty name="pinfo" property="age" value="28" />

 

 

<jsp:useBean id="pinfo2" class="mall.PersonalInfo" >

<jsp:setProperty name="pinfo2" property="name" value="전효성" />

<jsp:setProperty name="pinfo2" property="gender" value="" />

<jsp:setProperty name="pinfo2" property="age" value="22" />

</jsp:useBean>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>표준액션 : 자바빈 프로퍼티</title>

</head>

<body>

 

이름 : <jsp:getProperty name="pinfo" property="name" /><br>

성별 : <jsp:getProperty name="pinfo" property="gender" /><br>

나이 : <jsp:getProperty name="pinfo" property="age" /><br>

<br>

이름 : <jsp:getProperty name="pinfo2" property="name" /><br>

성별 : <jsp:getProperty name="pinfo2" property="gender" /><br>

나이 : <jsp:getProperty name="pinfo2" property="age" /><br>

<br>

<%

        out.println(pinfo2.getName() + "<br/>");

        out.println(pinfo2.getgender() + "<br/>");

        out.println(pinfo2.getAge() + "<br/>");

        /* jsp:useBean => 객체화 */

%>

 

 

</body>

</html>