본문 바로가기

JAVA/JSP & Servlet

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

 

 

 

 

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;

        }

       

}

 

 

 

CustomerInfo.jsp : 실행

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

    pageEncoding="UTF-8"%>

 

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

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

</head>

<body>

 

<form action="UseBeanEx03.jsp">

이름 : <input type="text" name="pname" /><br>

성별 : <input type="text" name="pgender" /><br>

나이 : <input type="text" name="page" /><br>

<input type="submit" value="확인" />

</form>

 

</body>

</html>

 

 

 

 

UseBeanEx03.jsp

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

    pageEncoding="UTF-8"%>

 

<%

        request.setCharacterEncoding("UTF-8");

%>

<!-- UseBeanEx03 -->

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

        <jsp:setProperty name="pinfo2" property="name"  param="pname" />

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

        <jsp:setProperty name="pinfo2" property="age"  param="page" />

</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,param)</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>