DB와 jsp 연동
- 사원정보 검색 테이블 만들기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
import="java.util.*"
import="jspexp.a13_database.*"
import="jspexp.a13_database.vo.*" // import 필수
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link href="/a00_com/a01_common.css" rel="stylesheet">
<script type="text/javascript">
function send(){
var frSalObj = document.querySelector("[name=frSal]")
var toSalObj = document.querySelector("[name=toSal]")
if((frSalObj.value.trim() =="" || isNaN(frSalObj.value))){
alert("공백이거나 숫자형 데이터가 아닙니다.")
frSalObj.value="";
frSalObj.focus()
return;
}
if((toSalObj.value.trim() =="" || isNaN(toSalObj.value))){
alert("공백이거나 숫자형 데이터가 아닙니다.")
toSalObj.value="";
toSalObj.focus()
return;
}
if(frSalObj.value>toSalObj.value){
alert("시작 범위가 마지막 범위보다 크네요.")
frSalObj.value=""
toSalObj.value=""
frSalObj.focus()
return;
}
document.querySelector("#frm01").submit()
}
</script>
</head>
<body>
<%
String ename=request.getParameter("ename"); if(ename==null) ename="";
String job=request.getParameter("job"); if(job==null) job="";
String frSal=request.getParameter("frSal"); if(frSal==null) frSal="0";
String toSal=request.getParameter("toSal"); if(toSal==null) toSal="9999";
double frSalD = Double.parseDouble(frSal);
double toSalD = Double.parseDouble(toSal);
A02_EmpDao dao = new A02_EmpDao(); // import한 자바 클래스 객체 생성
Emp sch = new Emp(ename, job, frSalD, toSalD); // vo 객체 생성
%>
<h2>사원정보</h2>
<form id="frm01">
<table>
<col width="40%">
<tr><th>사원명</th><td colspan="2"><input type="text" name="ename" value=<%=ename %>></td></tr>
<tr><th>직책</th><td colspan="2"><input type="text" name="job" value=<%=job %>></td></tr>
<tr><th>급여</th><td><input type="text" name="frSal" value="<%=frSal%>"></td>
<td><input type="text" name="toSal" value="<%=toSal%>"></td></tr>
<tr><td colspan="3"> <input type="button" onclick="send()" value="검색">
</td></tr>
</table>
</form>
<table>
<tr><th>사원번호</th><th>사원명</th><th>직책명</th>
<th>관리자번호</th><th>급여</th><th>부서번호</th>
</tr>
<%
for(Emp e:dao.getEmpSch(sch)){
%>
<tr>
<td><%=e.getEmpno() %></td>
<td><%=e.getEname() %></td>
<td><%=e.getJob() %></td>
<td><%=e.getMgr() %></td>
<td><%=e.getSal() %></td>
<td><%=e.getDeptno() %></td>
</tr>
<%} %>
</table>
</body>
<script type="text/javascript">
</script>
</html>