---------------------------------
직원 관리 JSP(JDBC) 프로그램
11. 소스코드
//Region.java
package com.test;
//자료형 클래스
public class Region {
//멤버변수
//regionId, regionName, delCheck
private String regionId, regionName;
private int delCheck; //0(삭제 가능) 또는 1 이상(삭제 불가능)의 숫자
public String getRegionId() {
return regionId;
}
public void setRegionId(String regionId) {
this.regionId = regionId;
}
public String getRegionName() {
return regionName;
}
public void setRegionName(String regionName) {
this.regionName = regionName;
}
public int getDelCheck() {
return delCheck;
}
public void setDelCheck(int delCheck) {
this.delCheck = delCheck;
}
}
//RegionDAO.java
package com.test;
import java.sql.*;
import java.util.*;
//데이터베이스 액션 클래스
public class RegionDAO {
//지역 명단 출력 메소드
public ArrayList<Region> regionList() {
ArrayList<Region> result = new ArrayList<Region>();
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = DBConn.getConnection();
//SELECT regionId, regionName, delCheck
// FROM regionView
// ORDER BY regionId;
String sql = "SELECT regionId, regionName, delCheck FROM regionView ORDER BY regionId";
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()) {
Region r = new Region();
r.setRegionId(rs.getString("regionId"));
r.setRegionName(rs.getString("regionName"));
r.setDelCheck(rs.getInt("delCheck"));
result.add(r);
}
rs.close();
}catch(Exception e){
e.printStackTrace();
}finally{
try {
if (pstmt != null) {
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
return result;
}
//지역 명단 입력 메소드
//지역 명단 삭제 메소드
}
//RegionListTest.java
package com.test;
public class RegionListTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
RegionDAO dao = new RegionDAO();
for (Region r : dao.regionList()) {
System.out.printf("%s %s %s %n"
, r.getRegionId()
, r.getRegionName()
, r.getDelCheck());
}
}
}
//RegionList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.test.*" %>
<%@ taglib prefix = "c" uri ="http://java.sun.com/jsp/jstl/core" %>
<%
StringBuilder sb = new StringBuilder();
RegionDAO dao = new RegionDAO();
for (Region r : dao.regionList()) {
sb.append(String.format("<tr>"));
sb.append(String.format("<td>%s</td>", r.getRegionId()));
sb.append(String.format("<td>%s</td>", r.getRegionName()));
sb.append(String.format("<td><input type=\"button\" value=\"삭제\" class=\"btnDelete\" %s></td>", (r.getDelCheck()>0)?"disabled=\"disabled\"":"" ));
sb.append(String.format("</tr>"));
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>직원관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="TableStyle.css">
<link rel="stylesheet" type="text/css" href="DivStyle.css">
</head>
<body>
<div>
<%--메뉴 영역--%>
<div class = "title">
<h1>직원관리 (JSP버전)</h1>
<c:import url="EmployeeMenu.jsp"></c:import>
</div>
<%--콘텐츠 영역--%>
<div class = "main">
<h2>[지역관리]</h2>
<form action="RegionInsert.jsp" method="post" id="myForm">
지역명* <input type = "text" id="regionName" name="regionName">
<input type = "submit" value = "지역추가">
<span id="msg"></span>
</form>
<table id ="t01" style = "font-size:10pt;">
<tr>
<th>지역번호</th><th>지역명</th><th>삭제</th>
</tr>
<!--
<tr>
<td>1</td>
<td>서울</td>
<td><input type = "button" value = "삭제" class = "btnDelete" disabled="disabled"></td>
</tr>
<tr>
<td>2</td>
<td>경기</td>
<td><input type = "button" value = "삭제" class="btnDelete" ></td>
</tr>
-->
<%=sb.toString()%>
</table>
</div>
</div>
</body>
</html>
---------------------------------------
문제) 부서관리, 직위관리 프로그램 출력 액션 작성
//Position.java -> 직위 정보 자료형 클래스
//Department.java -> 부서 정보 자료형 클래스
//PositionDAO.java -> JDBC 액션 클래스. 직위 정보 입출력 액션.
//DepartmentDAO.java -> JDBC 액션 클래스. 부서 정보 입출력 액션.
//PositionList.jsp -> 직위 정보 출력 페이지. 입력 폼 페이지. 삭제 버튼.
//DepartmentList.jsp -> 부서 정보 출력 페이지. 입력 폼 페이지. 삭제 버튼.
//Position.java -> 직위 정보 자료형 클래스
package com.test;
//자료형 클래스
public class Position {
//SELECT positionId, positionName, minBasicPay, delCheck FROM positionView ORDER BY positionId;
private String positionId,positionName;
private int delCheck,minBasicPay;
public String getPositionId() {
return positionId;
}
public void setPositionId(String positionId) {
this.positionId = positionId;
}
public String getPositionName() {
return positionName;
}
public void setPositionName(String positionName) {
this.positionName = positionName;
}
public int getMinBasicPay() {
return minBasicPay;
}
public void setMinBasicPay(int minBasicPay) {
this.minBasicPay = minBasicPay;
}
public int getDelCheck() {
return delCheck;
}
public void setDelCheck(int delCheck) {
this.delCheck = delCheck;
}
}
//Department.java -> 부서 정보 자료형 클래스
package com.test;
//자료형 클래스
public class Department {
//departmentId, departmentName, delCheck
private String departmentId, departmentName;
private int delCheck;
public String getDepartmentId() {
return departmentId;
}
public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public int getDelCheck() {
return delCheck;
}
public void setDelCheck(int delCheck) {
this.delCheck = delCheck;
}
}
//PositionDAO.java -> JDBC 액션 클래스. 직위 정보 입출력 액션.
package com.test;
import java.sql.*;
import java.util.*;
public class PositionDAO {
public ArrayList<Position> positionList(){
ArrayList<Position> result = new ArrayList<Position>();
Connection conn = null;
PreparedStatement pstmt =null;
try{
conn = DBConn.getConnection();
//SELECT positionId, positionName, minBasicPay, delCheck FROM positionView ORDER BY positionId;
String sql = String.format("SELECT positionId, positionName, minBasicPay, delCheck FROM positionView ORDER BY positionId");
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
Position p = new Position();
p.setPositionId(rs.getString("positionId"));
p.setPositionName(rs.getString("positionName"));
p.setMinBasicPay(rs.getInt("minBasicPay"));
p.setDelCheck(rs.getInt("delCheck"));
result.add(p); //컬렉션으로!
}
rs.close();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
return result;
}
}
//DepartmentDAO.java -> JDBC 액션 클래스. 부서 정보 입출력 액션.
package com.test;
import java.sql.*;
import java.util.*;
public class DepartmentDAO {
public ArrayList<Department> departmentList(){
ArrayList<Department> result = new ArrayList<Department>();
Connection conn = null;
PreparedStatement pstmt =null;
try{
conn = DBConn.getConnection();
//SELECT departmentId, departmentName, delCheck FROM departmentView ORDER BY departmentId;
String sql = String.format("SELECT departmentId, departmentName, delCheck FROM departmentView ORDER BY departmentId");
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
Department d = new Department();
d.setDepartmentId(rs.getString("departmentId"));
d.setDepartmentName(rs.getString("departmentName"));
d.setDelCheck(rs.getInt("delCheck"));
result.add(d); //컬렉션으로!
}
rs.close();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(pstmt!=null){
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
return result;
}
}
//PositionList.jsp -> 직위 정보 출력 페이지. 입력 폼 페이지. 삭제 버튼.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.test.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
StringBuilder sb = new StringBuilder();
PositionDAO dao = new PositionDAO();
for(Position p: dao.positionList()){
sb.append(String.format("<tr>"));
sb.append(String.format("<td>%s</td>",p.getPositionId()));
sb.append(String.format("<td>%s</td>",p.getPositionName()));
sb.append(String.format("<td >%,d</td>",p.getMinBasicPay()));
sb.append(String.format("<td><input type=\"button\" value=\"삭제\" class=\"btnDelete\" %s></td>",(p.getDelCheck()>0)?"disabled=\"disabled\"":""));
sb.append(String.format("</tr>"));
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>직원 관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="TableStyle.css">
<link rel="stylesheet" type="text/css" href="DivStyle.css">
</head>
<body>
<div>
<!-- 메뉴 영역 -->
<div class="title">
<%--
동일한 메뉴 디자인을 여러 페이지에 적용한 경우
수정 사항일 발생하면 모든 페이지를 동일하게 수정해야 한다.
->동일한 메뉴 디자인을 별도의 페이지로 작성
->필요하는 페이지에 동적 삽입
--%>
<h1>직원관리 (JSP버전)</h1>
<c:import url="EmployeeMenu.jsp"></c:import> <!-- 동적생성 -->
</div>
<!-- 콘텐츠 영역 -->
<div class="main">
<h2>-직위 관리-</h2>
<form action="PositionInsert.jsp" method="post" id="myForm">
직위명* <input type="text" name="positionName" id="positionName">
최소기본급* <input type="text" name="basicPay" id="basicPay">
<input type="submit" value="직위 추가">
</form>
<table id="t01" style="font-size : small;">
<!-- <tr>은 제목 -->
<tr>
<th>직위 번호</th>
<th>직위명</th>
<th>최소기본급</th>
<th>삭제</th>
</tr>
<!-- 샘플 디자인(가상으로 만든다) -->
<!--
<tr>
<td>1</td>
<td>사원</td>
<td>1000000</td>
id=""식별자 사용 불가, class=""식별자 사용:동일한 이름을 사용 하기 위해!
<td><input type="button" value="삭제" class="btnDelete" disabled="disabled"></td>
</tr>
<tr>
<td>2</td>
<td>대리</td>
<td>2000000</td>
id=""식별자 사용 불가, class=""식별자 사용:동일한 이름을 사용 하기 위해!
<td><input type="button" value="삭제" class="btnDelete" ></td>
</tr>
<tr>
<td>3</td>
<td>부장</td>
<td>2000000</td>
id=""식별자 사용 불가, class=""식별자 사용:동일한 이름을 사용 하기 위해!
<td><input type="button" value="삭제" class="btnDelete" ></td>
</tr>
-->
<%=sb.toString() %>
</table>
</div>
</div>
</body>
</html>
//DepartmentList.jsp -> 부서 정보 출력 페이지. 입력 폼 페이지. 삭제 버튼.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.test.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
StringBuilder sb = new StringBuilder();
DepartmentDAO dao = new DepartmentDAO();
for(Department d : dao.departmentList()){
sb.append(String.format("<tr>"));
sb.append(String.format("<td>%s</td>",d.getDepartmentId()));
sb.append(String.format("<td>%s</td>",d.getDepartmentName()));
sb.append(String.format("<td><input type=\"button\" value=\"삭제\" class=\"btnDelete\" %s></td>",(d.getDelCheck()>0)?"disabled=\"disabled\"":""));
sb.append(String.format("</tr>"));
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>직원 관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="TableStyle.css">
<link rel="stylesheet" type="text/css" href="DivStyle.css">
</head>
<body>
<div>
<!-- 메뉴 영역 -->
<div class="title">
<%--
동일한 메뉴 디자인을 여러 페이지에 적용한 경우
수정 사항일 발생하면 모든 페이지를 동일하게 수정해야 한다.
->동일한 메뉴 디자인을 별도의 페이지로 작성
->필요하는 페이지에 동적 삽입
--%>
<h1>직원관리 (JSP버전)</h1>
<c:import url="EmployeeMenu.jsp"></c:import> <!-- 동적생성 -->
</div>
<!-- 콘텐츠 영역 -->
<div class="main">
<h2>-부서 관리-</h2>
<form action="DepartmentInsert.jsp" method="post" id="myForm">
부서명* <input type="text" name="departmentName" id="departmentName">
<input type="submit" value="부서추가">
</form>
<table id="t01" style="font-size : small;">
<!-- <tr>은 제목 -->
<tr>
<th>부서 번호</th>
<th>부서명</th>
<th>삭제</th>
</tr>
<!-- 샘플 디자인(가상으로 만든다) -->
<!--
<tr>
<td>1</td>
<td>개발부</td>
id=""식별자 사용 불가, class=""식별자 사용:동일한 이름을 사용 하기 위해!
<td><input type="button" value="삭제" class="btnDelete" disabled="disabled"></td>
</tr>
<tr>
<td>2</td>
<td>마케팅부</td>
id=""식별자 사용 불가, class=""식별자 사용:동일한 이름을 사용 하기 위해!
<td><input type="button" value="삭제" class="btnDelete" ></td>
</tr>
<tr>
<td>3</td>
<td>영업부</td>
id=""식별자 사용 불가, class=""식별자 사용:동일한 이름을 사용 하기 위해!
<td><input type="button" value="삭제" class="btnDelete" ></td>
</tr>
-->
<%=sb.toString() %>
</table>
</div>
</div>
</body>
</html>
//Employee.java
package com.test;
public class Employee {
private String employeeId
, name
, birthday
, lunarName
, telephone
, departmentId
, departmentName
, positionId
, positionName
, regionId
, regionName;
private int lunar; // 0(양력) 또는 1(음력)
private int basicPay, extraPay, pay;
public String getEmployeeId() {
return employeeId;
}
public void setEmployeeId(String employeeId) {
this.employeeId = employeeId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getLunarName() {
return lunarName;
}
public void setLunarName(String lunarName) {
this.lunarName = lunarName;
}
public String getTelephone() {
return telephone;
}
public void setTelephone(String telephone) {
this.telephone = telephone;
}
public String getDepartmentId() {
return departmentId;
}
public void setDepartmentId(String departmentId) {
this.departmentId = departmentId;
}
public String getDepartmentName() {
return departmentName;
}
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
public String getPositionId() {
return positionId;
}
public void setPositionId(String positionId) {
this.positionId = positionId;
}
public String getPositionName() {
return positionName;
}
public void setPositionName(String positionName) {
this.positionName = positionName;
}
public String getRegionId() {
return regionId;
}
public void setRegionId(String regionId) {
this.regionId = regionId;
}
public String getRegionName() {
return regionName;
}
public void setRegionName(String regionName) {
this.regionName = regionName;
}
public int getLunar() {
return lunar;
}
public void setLunar(int lunar) {
this.lunar = lunar;
}
public int getBasicPay() {
return basicPay;
}
public void setBasicPay(int basicPay) {
this.basicPay = basicPay;
}
public int getExtraPay() {
return extraPay;
}
public void setExtraPay(int extraPay) {
this.extraPay = extraPay;
}
public int getPay() {
return pay;
}
public void setPay(int pay) {
this.pay = pay;
}
}
//EmployeeDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class EmployeeDAO {
//직원 명단 출력 메소드
public ArrayList<Employee>list(){
ArrayList<Employee> result = new ArrayList<Employee>();
Connection conn = null;
PreparedStatement pstmt = null;
try{
conn = DBConn.getConnection();
String sql = String.format("SELECT employeeId, name, birthday, lunar, lunarName, telephone, departmentId, departmentName, positionId, positionName, regionId, regionName, basicPay, extraPay, pay FROM employeeView ORDER BY employeeId");
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
Employee e = new Employee();
e.setEmployeeId(rs.getString("employeeId"));
e.setName(rs.getString("name"));
e.setBirthday(rs.getString("birthday"));
e.setLunar(rs.getInt("lunar"));
e.setLunarName(rs.getString("lunarName"));
e.setTelephone(rs.getString("telephone"));
e.setDepartmentId(rs.getString("departmentId"));
e.setDepartmentName(rs.getString("departmentName"));
e.setPositionId(rs.getString("positionId"));
e.setPositionName(rs.getString("positionName"));
e.setRegionId(rs.getString("regionId"));
e.setRegionName(rs.getString("regionName"));
e.setBasicPay(rs.getInt("basicPay"));
e.setExtraPay(rs.getInt("extraPay"));
e.setPay(rs.getInt("pay"));
result.add(e);
}
rs.close();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(pstmt != null){
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
return result;
}
//직원 검색 출력 메소드(검색기준 : 사번,주민번호,이름,지역,부서,직위)
public ArrayList<Employee> list(String searchKey, String searchValue){
ArrayList<Employee> result = new ArrayList<Employee>();
Connection conn = null;
PreparedStatement pstmt = null;
try{
conn = DBConn.getConnection();
String sql = String.format("SELECT employeeId, name, birthday, lunar, lunarName, telephone, departmentId, departmentName, positionId, positionName, regionId, regionName, basicPay, extraPay, pay FROM employeeView e");
switch(searchKey){
case "0" : sql += " WHERE employeeId=?"; break;
case "1" : sql += " WHERE ssn=encrypt(?, e.name)"; break;
case "2" : sql += " WHERE name=?"; break;
case "3" : sql += " WHERE regionName=?"; break;
case "4" : sql += " WHERE departmentName=?"; break;
case "5" : sql += " WHERE positionName=?"; break;
}
sql += " ORDER BY employeeId";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, searchValue);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
Employee e = new Employee();
e.setEmployeeId(rs.getString("employeeId"));
e.setName(rs.getString("name"));
e.setBirthday(rs.getString("birthday"));
e.setLunarName(rs.getString("lunarName"));
e.setTelephone(rs.getString("telephone"));
e.setDepartmentName(rs.getString("departmentName"));
e.setPositionName(rs.getString("positionName"));
e.setRegionName(rs.getString("regionName"));
e.setBasicPay(rs.getInt("basicPay"));
e.setExtraPay(rs.getInt("extraPay"));
e.setPay(rs.getInt("pay"));
result.add(e);
}
rs.close();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(pstmt != null){
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
return result;
}
//직원 전체 출력
public int count(){
int result = 0;
Connection conn = null;
PreparedStatement pstmt = null;
try{
conn = DBConn.getConnection();
String sql = String.format("select count(*) as \"count\" from employeeView");
pstmt = conn.prepareStatement(sql);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
result = rs.getInt("count");
}
rs.close();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(pstmt != null){
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
return result;
}
//직원 검색 결과 인원수 출력 메소드
public int count(String searchKey, String searchValue){
int result = 0;
Connection conn = null;
PreparedStatement pstmt = null;
try{
conn = DBConn.getConnection();
String sql = String.format("select count(*) as \"count\" from employeeView e");
switch(searchKey){
case "0" : sql += " WHERE employeeId=?"; break;
case "1" : sql += " WHERE ssn=encrypt(?, e.name)"; break;
case "2" : sql += " WHERE name=?"; break;
case "3" : sql += " WHERE regionName=?"; break;
case "4" : sql += " WHERE departmentName=?"; break;
case "5" : sql += " WHERE positionName=?"; break;
}
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, searchValue);
ResultSet rs = pstmt.executeQuery();
while(rs.next()){
result = rs.getInt("count");
}
rs.close();
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(pstmt != null){
pstmt.close();
}
}catch(Exception e){
}
DBConn.close();
}
return result;
}
}
//EmployeeList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "com.test.*" %>
<%@ taglib prefix = "c" uri ="http://java.sun.com/jsp/jstl/core" %>
<%
StringBuilder sb = new StringBuilder();
int count = 0;
EmployeeDAO dao = new EmployeeDAO();
count = dao.count();
for(Employee e : dao.list()){
//번호, 이름, 생일,양음력,전번,부서명,직위명,지역명,기본급,수당,급여,삭제
sb.append(String.format("<tr>\r\n"));
sb.append(String.format("<td>%s</td>", e.getEmployeeId() ));
sb.append(String.format("<td>%s</td>", e.getName() ));
sb.append(String.format("<td>%s</td>", e.getBirthday() ));
sb.append(String.format("<td>%s</td>", e.getLunarName() ));
sb.append(String.format("<td>%s</td>", e.getTelephone() ));
sb.append(String.format("<td>%s</td>", e.getDepartmentName() ));
sb.append(String.format("<td>%s</td>", e.getPositionName() ));
sb.append(String.format("<td>%s</td>", e.getRegionName() ));
sb.append(String.format("<td style = \"text-align : right;\">%,d</td>", e.getBasicPay() ));
sb.append(String.format("<td style = \"text-align : right;\">%,d</td>", e.getExtraPay() ));
sb.append(String.format("<td style = \"text-align : right;\">%,d</td>", e.getPay() ));
sb.append(String.format("<td><input type = \"button\" value = \"삭제\" class = \"btnDelete\"></td>"));
sb.append(String.format("</tr>\r\n"));
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>직원관리(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="TableStyle.css">
<link rel="stylesheet" type="text/css" href="DivStyle.css">
</head>
<body>
<div>
<%--메뉴 영역--%>
<div class = "title">
<%--
동일한 메뉴 디자인을 여러 페이지에 적용한 경우
수정 사항이 발생하면 모든 페이지를 동일하게 수정해야 한다.
-> 동일한 메뉴 디자인을 별도의 페이지로 작성
-> 필요하는 페이지에 동적 삽입
--%>
<h1>직원관리 (JSP버전)</h1>
<c:import url="EmployeeMenu.jsp"></c:import>
</div>
<%--콘텐츠 영역--%>
<div class = "main">
<h2>[직원명단]</h2>
<form>
<input type = "button" value = "직원추가" id = "btnAdd" name = "btnAdd">
<input type = "button" value = "직원검색" id = "btnSearch" name = "btnSearch" onclick = "location.href = 'EmployeeSearch.jsp'">
</form>
<!-- <p>직원수 : 1명</p> -->
<p>직원수 : <%=count%> 명</p>
<table id ="t01" style = "font-size:10pt;">
<tr>
<th>직원번호</th><th>이름</th><th>생년월일</th><th>양음력</th><th>전화번호</th>
<th>부서명</th><th>직위명</th><th>지역명</th><th>기본급</th><th>수당</th><th>급여</th><th>삭제</th>
</tr>
<%-- <tr>
<td>1</td><td>홍길동</td><td>1991-03-01</td><td>양력</td><td>010-1234-1234</td>
<td>개발부</td><td>사원</td><td>서울</td>
<td style = "text-align: right;">1,000,000</td>
<td style = "text-align: right;">500,000</td>
<td style = "text-align: right;">1,500,000</td>
id ="" 식별자 사용 불가 ->반복문을 사용하기 떄문에
중복이 가능한 식별자 class =""를 사용한다.
<td><input type = "button" value = "삭제" class = "btnDelete"></td>
</tr> --%>
<%= sb.toString()%>
</table>
</div>
</div>
</body>
</html>
//EmployeeSearch.java
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="com.test.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
request.setCharacterEncoding("UTF-8");
StringBuilder sb = new StringBuilder();
int count = 0;
//사용자가 선택한 키와 값을 전달 받아서 검색 과정을 진행
//-> 최초 실행시 키와 값이 전달되지 않습니다.
String searchKey = request.getParameter("searchKey");
String searchValue = request.getParameter("searchValue");
//전달된 값이 있는 경우만 검색 과정 진행!
if (searchKey != null) {
EmployeeDAO dao = new EmployeeDAO();
count = dao.count(searchKey, searchValue);
for (Employee e : dao.list(searchKey, searchValue)) {
//번호, 이름, 생일,양음력,전번,부서명,직위명,지역명,기본급,수당,급여,삭제
sb.append(String.format("<tr>\r\n"));
sb.append(String.format("<td>%s</td>", e.getEmployeeId() ));
sb.append(String.format("<td>%s</td>", e.getName()));
sb.append(String.format("<td>%s</td>", e.getBirthday()));
sb.append(String.format("<td>%s</td>", e.getLunarName()));
sb.append(String.format("<td>%s</td>", e.getTelephone()));
sb.append(String.format("<td>%s</td>", e.getDepartmentName()));
sb.append(String.format("<td>%s</td>", e.getPositionName()));
sb.append(String.format("<td>%s</td>", e.getRegionName()));
sb.append(String.format("<td style = \"text-align : right;\">%,d</td>", e.getBasicPay() ));
sb.append(String.format("<td style = \"text-align : right;\">%,d</td>", e.getExtraPay() ));
sb.append(String.format("<td style = \"text-align : right;\">%,d</td>", e.getPay() ));
sb.append(String.format("<td><input type = \"button\" value = \"삭제\" class = \"btnDelete\"></td>"));
sb.append(String.format("</tr>\r\n"));
}
}
if (searchValue == null) {
searchValue = "";
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>직원검색(JSP버전)</title>
<link rel="stylesheet" type="text/css" href="TableStyle.css">
<link rel="stylesheet" type="text/css" href="DivStyle.css">
<script type="text/javascript">
window.onload=function() {
var searchKeys = document.getElementsByName("searchKey");
for (var i=0; i<searchKeys.length; ++i) {
var searchKey = searchKeys[i];
if (searchKey.value == "<%=searchKey%>") {
searchKey.checked = true;
}
}
};
</script>
</head>
<body>
<div>
<%--메뉴 영역--%>
<div class="title">
<h1>직원관리 (JSP버전)</h1>
<c:import url="EmployeeMenu.jsp"></c:import>
</div>
<%--콘텐츠 영역--%>
<div class="main">
<h2>[직원검색]</h2>
<form id="t01">
<input type="button" value="직원명단" id="btnList" name="btnList" onclick = "location.href = 'EmployeeList.jsp'">
<input type="button" value="직원추가" id="btnAdd" name="btnAdd">
</form>
<form method="post" id="myForm">
<p>
[검색기준]
<input type="radio" name="searchKey" value="0" checked="checked">사번
<input type="radio" name="searchKey" value="1">주민번호
<input type="radio" name="searchKey" value="2">이름
<input type="radio" name="searchKey" value="3">지역
<input type="radio" name="searchKey" value="4">부서
<input type="radio" name="searchKey" value="5">직위
</p>
<p>
검색단어 <input type="text" id="searchValue" name = "searchValue" value="<%=searchValue%>">
<input type="submit" value="직원검색">
</p>
</form>
<p>검색 직원수 : <%=count %>명</p>
<table id="t01" style="font-size:10pt;">
<tr>
<th>직원번호</th>
<th>이름</th>
<th>생년월일</th>
<th>양음력</th>
<th>전화번호</th>
<th>부서명</th>
<th>직위명</th>
<th>지역명</th>
<th>기본급</th>
<th>수당</th>
<th>급여</th>
<th>삭제</th>
</tr>
<%-- <tr>
<td>1</td>
<td>홍길동</td>
<td>1991-03-01</td>
<td>양력</td>
<td>010-1234-1234</td>
<td>개발부</td>
<td>사원</td>
<td>서울</td>
<td style="text-align: right;">1,000,000</td>
<td style="text-align: right;">500,000</td>
<td style="text-align: right;">1,500,000</td>
id ="" 식별자 사용 불가 ->반복문을 사용하기 떄문에
중복이 가능한 식별자 class =""를 사용한다.
<td><input type="button" value="삭제" class="btnDelete"></td>
</tr> --%>
<%=sb.toString() %>
</table>
</div>
</div>
</body>
</html>
-----------------------------------------