package com.test;
public class PersonDTO {
private String name;
private int age;
public PersonDTO() {
super();
}
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;
}
}
<!-- 03_javabeans/personForm.jsp -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>personForm</title>
<!--
# 아래의 입력값을 사용해서 'personPro.jsp' 에서 PersonDTO class 객체를 생성해서 결과를 출력하세요
- package : com.test
- jsp 액션 태그를 사용합니다
-->
</head>
<body>
<h1>정보 입력</h1>
<form action="personPro.jsp" method="post">
이 름 : <input type="text" name="name"/>
<br/><br/>
나 이 : <input type="text" name="age"/>
<br/><br/>
<input type="submit" value="전송"/>
</form>
</body>
</html>
<%@page import="com.test.PersonDTO"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
int age = Integer.parseInt(request.getParameter("age"));
PersonDTO person = new PersonDTO();
%>
<jsp:useBean id="userA" class="com.test.PersonDTO" scope="page">
<jsp:setProperty name="userA" property="name" value="<%=name %>"/>
<jsp:setProperty name="userA" property="age" value="<%=age %>"/>
</jsp:useBean>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>personPro</title>
</head>
<body>
<p>입력한 이름 : <jsp:getProperty name="userA" property="name"/></p>
<p>입력한 나이 : <jsp:getProperty name="userA" property="age"/> 세</p>
</body>
</html>