----------------------------------------

//Employee_Search.jsp

<%@page import="java.net.URLDecoder"%>

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="com.test.*" %>

<%


request.setCharacterEncoding("euc-kr");

String key = request.getParameter("key");

if (key == null) {

key = "";

}

String value = request.getParameter("value");

if (value == null) {

value = "";

}


String order = request.getParameter("order");

if (order == null) {

order = "emp_id";

}

String direction = request.getParameter("direction");

if (direction == null) {

direction = "asc";

}

//제목을 기준으로 정렬시키기 위해서 추가한 부분

String urlEmp_id = "";

String urlName = "";

String urlSsn = "";

String urlIbsadate = "";

String urlCity = "";

String urlTel = "";

String urlBuseo = "";

String urlJikwi = "";

String urlBasicpay = "";

String urlSudang = "";

String urlPay = "";

//제목을 기준으로 정렬시키기 위해서 추가한 부분

if (order.equals("emp_id") && direction.equals("asc")) {

urlEmp_id = String.format("Employee_Search.jsp?order=emp_id&direction=desc&key=%s&value=%s", key, value);

} else {

urlEmp_id = String.format("Employee_Search.jsp?order=emp_id&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("name") && direction.equals("asc")) {

urlName = String.format("Employee_Search.jsp?order=name&direction=desc&key=%s&value=%s", key, value);

} else {

urlName = String.format("Employee_Search.jsp?order=name&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("ssn") && direction.equals("asc")) {

urlSsn = String.format("Employee_Search.jsp?order=ssn&direction=desc&key=%s&value=%s", key, value);

} else {

urlSsn = String.format("Employee_Search.jsp?order=ssn&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("ibsadate") && direction.equals("asc")) {

urlIbsadate = String.format("Employee_Search.jsp?order=ibsadate&direction=desc&key=%s&value=%s", key, value);

} else {

urlIbsadate = String.format("Employee_Search.jsp?order=ibsadate&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("city") && direction.equals("asc")) {

urlCity = String.format("Employee_Search.jsp?order=city&direction=desc&key=%s&value=%s", key, value);

} else {

urlCity = String.format("Employee_Search.jsp?order=city&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("tel") && direction.equals("asc")) {

urlTel = String.format("Employee_Search.jsp?order=tel&direction=desc&key=%s&value=%s", key, value);

} else {

urlTel = String.format("Employee_Search.jsp?order=tel&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("buseo") && direction.equals("asc")) {

urlBuseo = String.format("Employee_Search.jsp?order=buseo&direction=desc&key=%s&value=%s", key, value);

} else {

urlBuseo = String.format("Employee_Search.jsp?order=buseo&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("jikwi") && direction.equals("asc")) {

urlJikwi = String.format("Employee_Search.jsp?order=jikwi&direction=desc&key=%s&value=%s", key, value);

} else {

urlJikwi = String.format("Employee_Search.jsp?order=jikwi&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("basicpay") && direction.equals("asc")) {

urlBasicpay = String.format("Employee_Search.jsp?order=basicpay&direction=desc&key=%s&value=%s", key, value);

} else {

urlBasicpay = String.format("Employee_Search.jsp?order=basicpay&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("sudang") && direction.equals("asc")) {

urlSudang = String.format("Employee_Search.jsp?order=sudang&direction=desc&key=%s&value=%s", key, value);

} else {

urlSudang = String.format("Employee_Search.jsp?order=sudang&direction=asc&key=%s&value=%s", key, value);

}

if (order.equals("pay") && direction.equals("asc")) {

urlPay = String.format("Employee_Search.jsp?order=pay&direction=desc&key=%s&value=%s", key, value);

} else {

urlPay = String.format("Employee_Search.jsp?order=pay&direction=asc&key=%s&value=%s", key, value);

}


StringBuilder str = new StringBuilder();

String count = "0";

EmployeeDAO dao = new EmployeeDAO();

try {

dao.connect();

String wheres = String.format("WHERE %s='%s'", key, value);

String orders = String.format("ORDER BY %s %s", order, direction);


count = String.valueOf(dao.count(wheres));

for (EmployeeDTO dto : dao.searchLists(wheres,orders)) {

str.append(String.format("<tr>"));

str.append(String.format("<td class=\"style1\">%d</td>", dto.getEmp_id()));

str.append(String.format("<td class=\"style1\">%s</td>", dto.getName()));

str.append(String.format("<td class=\"style1\">%s</td>", dto.getSsn()));

str.append(String.format("<td class=\"style1\">%s</td>", dto.getIbsadate()));

str.append(String.format("<td class=\"style1\">%s</td>", dto.getCity()));

str.append(String.format("<td class=\"style1\">%s</td>", dto.getTel()));

str.append(String.format("<td class=\"style1\">%s</td>", dto.getBuseo()));

str.append(String.format("<td class=\"style1\">%s</td>", dto.getJikwi()));

str.append(String.format("<td class=\"style2\">%,d</td>", dto.getBasicpay()));

str.append(String.format("<td class=\"style2\">%,d</td>", dto.getSudang()));

str.append(String.format("<td class=\"style2\">%,d</td>", dto.getPay()));

str.append(String.format("</tr>"));

}

}catch(Exception e){

System.out.println(e.toString());

}finally{

dao.close();

}

%>    

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">

<title>직원관리(JSP버전)</title>


<link rel="stylesheet" type="text/css" href="BasicStyle.css">


<script type="text/javascript">


function search() {

var myForm = document.getElementById("myForm");

//문제) 데이터 검사 과정 추가할 것.

//데이터 전송

myForm.submit();

}

function radioCheck() {

var obj = document.getElementById("<%=key%>");

obj.checked = true;

}

</script>


</head>

<body onload="radioCheck()">

<div>

<div>

<h2>직원관리_직원검색</h2>

<div>

[<a href="Employee_Select.jsp">직원출력</a>]

[<a href="Employee_Search.jsp">직원검색</a>]

[<a href="Employee_InsertForm.jsp">직원입력</a>]

[<a href="Employee_UpdateForm.jsp">직원수정</a>]

[<a href="Employee_DeleteForm.jsp">직원삭제</a>]

[<a href="City.jsp">지역관리</a>]

[<a href="Buseo.jsp">부서관리</a>]

[<a href="Jikwi.jsp">직위관리</a>]

[<a href="Logout.jsp">로그아웃</a>]

</div>

<hr>

</div>

<div>

<form method="get" id="myForm">

검색기준 

<input type="radio" name="key" value="emp_id" id="emp_id">사번

<input type="radio" name="key" value="name" id="name">이름

<input type="radio" name="key" value="city" id="city">지역

<input type="radio" name="key" value="buseo" id="buseo">부서

<input type="radio" name="key" value="jikwi" id="jikwi">직위

<input type="text" style="width:200px;"

name="value" id="value" value="<%=value%>">

[<a href="javascript:search()">검색</a>]

<span id="searchMsg" style="color:red;display:none;">검색 기준 또는 검색 단어를 채워야 합니다.</span>

</form>

<h3>검색 결과 직원수 : <%=count%>명</h3>

<div id="result">

<table style="width:900px;" class="style00">

<tbody>

<tr>

<th><a href="<%=urlEmp_id%>">사번</a></th>

<th><a href="<%=urlName%>">이름</a></th>

<th><a href="<%=urlSsn%>">주민번호</a></th>

<th><a href="<%=urlIbsadate%>">입사일</a></th>

<th><a href="<%=urlCity%>">지역</a></th>

<th><a href="<%=urlTel%>">전화번호</a></th>

<th><a href="<%=urlBuseo%>">부서</a></th>

<th><a href="<%=urlJikwi%>">직위</a></th>

<th><a href="<%=urlBasicpay%>">기본급</a></th>

<th><a href="<%=urlSudang%>">수당</a></th>

<th><a href="<%=urlPay%>">급여</a></th>

</tr>

<%=str%>

</tbody>

</table>

</div>

</div>

</div>

</body>

</html>



* 검색 결과 출력 후 제목 클릭시 정렬하는 부분.

-> 한글에 대한 get 방식 데이터 전송 문제

-> 해결 방법은 server.xml에서 

<Connector connectionTimeout="20000" port="8090" protocol="HTTP/1.1" redirectPort="8443"/>

부분을 

<Connector connectionTimeout="20000" port="8090" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="euc-kr"/>

로 고칠 것.

------------------------------------------------





WRITTEN BY
빨강꼬마

,