Notice
Recent Posts
Recent Comments
Link
«   2024/06   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

Insert 본문

JSP/DB (3)

Insert

GAWON 2023. 6. 1. 09:20
<%@page import="org.joonzis.ex.GreenDao"%>
<%@page import="org.joonzis.ex.GreenDto"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	request.setCharacterEncoding("utf-8");
	String id = request.getParameter("id");
	String pw = request.getParameter("pw");
	String name = request.getParameter("name");
	String age = request.getParameter("age");
	String addr = request.getParameter("addr");

	GreenDto dto = new GreenDto();
	dto.setId(id);
	dto.setPw(pw);
	dto.setName(name);
	dto.setAge(Integer.parseInt(age));
	dto.setAddr(addr);
	
	//dao로 dto전달
	//dao에서 전달 받은 dto를 이용하여 데이터 삽입 후 결과 값 리턴
	//전달 받은 데이터(삽입 후)를 판단하여 진행
	
	int result = GreenDao.getInstance().getInsert(dto);
	
	pageContext.setAttribute("result", result);
%>

	<c:choose>
		<c:when test="${result gt 0 }"> <!-- 0보다 크면  -->
			<script type="text/javascript">
				alert("회원이 추가되었습니다.");
				location.href='view_all.jsp'; <!-- 화면이동  -->
			</script>
		</c:when>
		<c:otherwise>
			<script type="text/javascript">
				alert("회원이 추가를 실패했습니다.");
				location.href='view_all.jsp'; <!-- 화면이동  -->
			</script>
		</c:otherwise>
	</c:choose>
</body>
</html>

'JSP > DB (3)' 카테고리의 다른 글

Update  (0) 2023.06.01
Remove  (0) 2023.06.01
index  (0) 2023.06.01
GreenDao  (0) 2023.06.01
GreenDto  (0) 2023.06.01