1) Beantest.java
package test;
public class Beantest {
private String name;
private String addr;
private String email;
private String birthday;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
}
beantest.html
<!DOCTYPE html>
<html>
<style>
#formArea{
margin:auto;
width:400px;
border:1px solid black;
}
h1,fieldset{
text-align:center;
}
</style>
<head>
<meta charset="UTF-8">
<title>Bean Test</title>
</head>
<body>
<section id="formArea">
<h1>propery="*" 테스트</h1>
<form action="beanTest.jsp" method="post">
<fieldset>
<label for="name">이름: </label> <input type="text" name="name" id="name"> <br>
<label for="addr">주소: </label> <input type="text" name="addr" id="addr"> <br>
<label for="email">이메일주소: </label> <input type="email" name="email" id="email"> <br>
<label for="birthday">생년월일: </label> <input type="date" name="birthday" id="birthday"> <br>
<input type="submit" value="전송">
</fieldset>
</form>
</section>
</body>
</html>
beaTest.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<% request.setCharacterEncoding("UTF-8"); %>
<jsp:useBean id="beantest" class="test.Beantest" scope="page"></jsp:useBean>
<jsp:setProperty property="*" name="beantest"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JavaBean Test</title>
</head>
<body>
<h1>자바빈 속성 값 출력</h1>
<b>이름: </b> <%=beantest.getName() %> <br>
<b>주소: </b> <%=beantest.getAddr() %> <br>
<b>이메일 주소: </b> <%=beantest.getEmail() %> <br>
<b>생년월일: </b> <%=beantest.getBirthday() %> <br>
</body>
</html>
property="*"로 설정하면 클라이언트에서 전송되어오는 파라미터 값이 모두 같은 이름의 빈 객체의 속성 값으로 자동 할당된다
'Web > JSP' 카테고리의 다른 글
세션(Session)과 쿠키(Cookie) (0) | 2022.01.25 |
---|---|
자바빈(Java Bean) (0) | 2022.01.21 |
Servlet을 사용한 로그인 기능 구현 (0) | 2022.01.20 |
Servlet의 핵심 사항들 + 로그인, 회원가입 예제 (0) | 2022.01.18 |
[JSP] Servlet request, response (0) | 2022.01.18 |