본문 바로가기

JAVA/JSP & Servlet

표준 액션(standard action) : useBean (scope)

 

 

 

 

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;

        }

       

}

 

 

 

UseBeanEx02.jsp : 실행

 

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

    pageEncoding="UTF-8"%>

 

<!-- scope="request" : request 객체가 살아있는동안 값을 유지. 만약 page라면 page내에서만 유지 -->

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

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

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

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

</jsp:useBean>

 

<jsp:forward page="CustomerInfoViewer.jsp"></jsp:forward>

 

 

 

CustomerInfoViewer.jsp

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

    pageEncoding="UTF-8"%>

 

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

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

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

</head>

<body>

 

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

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

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

 

</body>

</html>