자바빈을 이용하여 영화정보를 작성해보자
package com.mission.javabeans;
public class MovieBean {
private String title;
private int price;
private String director;
private String actor;
private String synopsis;
private String genre;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
public String getActor() {
return actor;
}
public void setActor(String actor) {
this.actor = actor;
}
public String getSynopsis() {
return synopsis;
}
public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
}
<05_movieWriteForm.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form method="POST" action="05_movieWrite.jsp">
<table>
<thead>
<h2>게시판 글쓰기</h2>
</thead>
<tr>
<td><b>제목</b></td>
<td><input type="text" name="title"></td>
</tr>
<tr>
<td><b>가격</b></td>
<td><input type="text" name="price"></td>
</tr>
<tr>
<td><b>감독</b></td>
<td><input type="text" name="director"></td>
</tr>
<tr>
<td><b>출연배우</b></td>
<td><input type="text" name="actor"></td>
</tr>
<tr>
<td><b>설명</b></td>
<td><textarea rows="10" cols="80" name="synopsis"></textarea></td>
</tr>
<tr>
<td><b>장르</b></td>
<td><select name="genre" size="1">
<option value="">선택해주세요</option>
<option value="코미디">코미디</option>
<option value="로맨틱">로맨틱</option>
<option value="액션">액션</option>
<option value="느와르">느와르</option>
<option value="공포">공포</option>
<option value="SF">SF</option>
</select></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="등록"><input type="reset" value="다시하기"></td>
</tr>
</table>
</form>
</body>
</html>
<05_movieWrite.jsp>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
%>
<jsp:useBean class="com.mission.javabeans.MovieBean" id="movie" scope="page" />
<jsp:setProperty property="title" name="movie" value='<%=request.getParameter("title")%>' />
<jsp:setProperty property="price" name="movie" value='<%=Integer.parseInt(request.getParameter("price"))%>' />
<jsp:setProperty property="director" name="movie" value='<%=request.getParameter("director")%>' />
<jsp:setProperty property="actor" name="movie" value='<%=request.getParameter("actor")%>' />
<jsp:setProperty property="synopsis" name="movie" value='<%=request.getParameter("synopsis")%>' />
<jsp:setProperty property="genre" name="movie" value='<%=request.getParameter("genre")%>' />
<table>
<thead>
<h2>영화 정보</h2>
</thead>
<tr>
<td><b>제목</b></td>
<td><jsp:getProperty name="movie" property="title" /></td>
</tr>
<tr>
<td><b>가격</b></td>
<td><jsp:getProperty name="movie" property="price" /></td>
</tr>
<tr>
<td><b>감독</b></td>
<td><jsp:getProperty name="movie" property="director" /></td>
</tr>
<tr>
<td><b>출연배우</b></td>
<td><jsp:getProperty name="movie" property="actor" /></td>
</tr>
<tr>
<td><b>설명</b></td>
<td><jsp:getProperty name="movie" property="synopsis" /></td>
</tr>
<tr>
<td><b>장르</b></td>
<td><jsp:getProperty name="movie" property="genre" /></td>
</tr>
</table>
</body>
</html>
728x90
반응형
'JSP, Servlet > JSP, Servlet 기초' 카테고리의 다른 글
[JSP] 표현언어와 기존방식으로 데이터 읽어오기 (0) | 2020.08.12 |
---|---|
[JSP] 표현 언어(EL : Expression Laguage) (0) | 2020.08.12 |
[JSP/Servlet] 자바빈을 이용하여 상품정보 등록하기 (0) | 2020.08.12 |
[JSP/Servlet] 자바빈을 이용하여 게시판 만들기 (0) | 2020.08.12 |
[JSP/Servlet] 자바빈을 이용하여 회원가입 페이지 만들기 (0) | 2020.08.12 |