dto-ssinsertform-dao--ssinsertaction
sinsangDto.java
package sinsang.model;
public class SinsangDto {
private String num;
private String name;
private String blood;
private String hp;
private String birth;
//setter,getter
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBlood() {
return blood;
}
public void setBlood(String blood) {
this.blood = blood;
}
public String getHp() {
return hp;
}
public void setHp(String hp) {
this.hp = hp;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ssinsertform.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>
<link href="https://fonts.googleapis.com/css2?family=Nanum+Pen+Script&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script type="text/javascript">
/* 연락처에서 입력창 이동 */
function goFocus(hp) {
if(hp.value.length==4)
frm.hp3.focus();
}
</script>
</head>
<body>
<form action="ssinsertaction.jsp" method="post" name="frm">
<table class="table table-bordered" style="width: 350px;">
<caption>신상정보</caption>
<tr>
<th width="100">이름</th>
<td>
<input type="text" name="name" size="8" placeholder="이름" required="required">
</td>
</tr>
<tr>
<th width="100">혈액형</th>
<td>
<select name="blood" size="1">
<option value="A">A형</option>
<option value="B">B형</option>
<option value="O">O형</option>
<option value="AB">AB형</option>
</select>
</td>
</tr>
<tr>
<th width="100">연락처</th>
<td>
<select size="1" name="hp1">
<option value="010">010</option>
<option value="010">011</option>
<option value="010">019</option>
<option value="010">02</option>
<option value="010">031</option>
</select>
<b>-</b>
<input type="text" name="hp2" size="3" required="required"
onkeyup="goFocus(this)">
<b>-</b>
<input type="text" name="hp3" size="3" required="required">
</td>
</tr>
<tr>
<th width="100">생년월일</th>
<td>
<input type="date" name="birth" required="required">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="DB저장">
<input type="button" value="목록" onclick="location.href='sslist.jsp'">
</td>
</tr>
</table>
</form>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sinsangDao.java
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ssinsertaction.jsp
<%@page import="sinsang.model.SinsangDao"%>
<%@page import="sinsang.model.SinsangDto"%>
<%@ 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>
<link href="https://fonts.googleapis.com/css2?family=Nanum+Pen+Script&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.5.0.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String name=request.getParameter("name");
String blood=request.getParameter("blood");
String birth=request.getParameter("birth");
//db에서는 hp하나이기에 hp1,2,3 묶어주기
String hp=request.getParameter("hp1")+"-"+
request.getParameter("hp2")+"-"+request.getParameter("hp3");
//dto생성해서 담기
SinsangDto dto=new SinsangDto();
dto.setName(name);
dto.setBlood(blood);
dto.setHp(hp);
dto.setBirth(birth);
//dao생성해서 insert메서드 호출
SinsangDao dao=new SinsangDao();
dao.sinsangInsert(dto);
//목록으로 이동
response.sendRedirect("sslist.jsp");
%>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'JSP' 카테고리의 다른 글
211020_session (0) | 2021.10.20 |
---|---|
211020_session으로 로그인/로그아웃 (0) | 2021.10.20 |
211019_복습(jsp) (0) | 2021.10.19 |
211019_jsp로 게시판 만들기 (0) | 2021.10.19 |
211012_form전송(checkbox, radio,select,array) (0) | 2021.10.12 |