--------------------------------
로그인, 로그아웃
1. Session 객체. JSP의 내장 객체 중에서 한 종류.
2. JSP 내장 객체. 객체 생성 과정 없이 바로 사용 가능한 객체.
- request
- response
- out
- session
JSP (JSP 문법 코드) -> (자동 컴파일) -> Servlet (순수 자바 소스 코드)
-> request는 HttpServletRequest 객체로 생성되는 과정이 자동 포함됨.
response는 HttpServletResponse 객체로 생성되는 과정이 자동 포함됨.
3. session 객체는 JSP 페이지에 대해서 독립적인 저장소 역할.
JSP 내부에서 변수 선언시 -> 지역 변수
다른 JSP에서 변수의 값을 사용하려면?
-> 데이터 송수신 과정 필요. 1 대 1만 가능.
로그인 정보처럼 여러 페이지에 인식해야 되는 정보는 송수신 과정으로는 처리 불가능.
-> 독립적인 저장소 필요 -> 세션
4. session.setAttribute(), session.getAttribute(), session.removeAttribute()
--------------------------------------------
JSTL 기능 구현
1. standard.jar, jstl.jar 파일을 프로젝트의 WebContent>WEB-INF>lib 폴더에 복사할 것.
2. import 구문 사용 가능
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:import url="JSP 파일"></c:import>
3. if 구문 사용 가능. else 표현은 없다. 조건식은 표현식으로 구성.
<c:if test="조건"></c:if>
--------------------------------------------
직원관리 (JSP버전) 최종 소스 코드
----------------------------------------------
//DBConn.java
package com.test;
import java.sql.*;
public class DBConn {
//Singleton pattern
private static Connection dbConn;
public static Connection getConnection()
throws SQLException, ClassNotFoundException {
if (dbConn == null) {
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String user = "scott";
String pw = "tiger";
Class.forName("oracle.jdbc.driver.OracleDriver");
dbConn = DriverManager.getConnection(url, user, pw);
}
return dbConn;
}
public static void close()
throws SQLException {
if (dbConn != null) {
if (!dbConn.isClosed()) {
dbConn.close();
}
}
dbConn = null;
}
}
----------------------------------------------
//EmployeeDTO.java
package com.test;
public class EmployeeDTO {
//멤버변수
private int emp_id, city_id, buseo_id, jikwi_id;
private int min_basicpay, basicpay, sudang, pay;
private String ibsadate; //날짜지만 문자열로 취급
private String name, ssn, city, buseo, jikwi, tel;
//getter, setter
public int getEmp_id() {
return emp_id;
}
public void setEmp_id(int emp_id) {
this.emp_id = emp_id;
}
public int getCity_id() {
return city_id;
}
public void setCity_id(int city_id) {
this.city_id = city_id;
}
public int getBuseo_id() {
return buseo_id;
}
public void setBuseo_id(int buseo_id) {
this.buseo_id = buseo_id;
}
public int getJikwi_id() {
return jikwi_id;
}
public void setJikwi_id(int jikwi_id) {
this.jikwi_id = jikwi_id;
}
public int getMin_basicpay() {
return min_basicpay;
}
public void setMin_basicpay(int min_basicpay) {
this.min_basicpay = min_basicpay;
}
public int getBasicpay() {
return basicpay;
}
public void setBasicpay(int basicpay) {
this.basicpay = basicpay;
}
public int getSudang() {
return sudang;
}
public void setSudang(int sudang) {
this.sudang = sudang;
}
public int getPay() {
return pay;
}
public void setPay(int pay) {
this.pay = pay;
}
public String getIbsadate() {
return ibsadate;
}
public void setIbsadate(String ibsadate) {
this.ibsadate = ibsadate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSsn() {
return ssn;
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getBuseo() {
return buseo;
}
public void setBuseo(String buseo) {
this.buseo = buseo;
}
public String getJikwi() {
return jikwi;
}
public void setJikwi(String jikwi) {
this.jikwi = jikwi;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
}
----------------------------------------------
//CityDTO.java
package com.test;
public class CityDTO {
private int city_id;
private String city;
public int getCity_id() {
return city_id;
}
public void setCity_id(int city_id) {
this.city_id = city_id;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
}
----------------------------------------------
//BuseoDTO.java
package com.test;
public class BuseoDTO {
private int buseo_id;
private String buseo;
public int getBuseo_id() {
return buseo_id;
}
public void setBuseo_id(int buseo_id) {
this.buseo_id = buseo_id;
}
public String getBuseo() {
return buseo;
}
public void setBuseo(String buseo) {
this.buseo = buseo;
}
}
----------------------------------------------
//JikwiDTO.java
package com.test;
public class JikwiDTO {
private int jikwi_id;
private String jikwi;
public int getJikwi_id() {
return jikwi_id;
}
public void setJikwi_id(int jikwi_id) {
this.jikwi_id = jikwi_id;
}
public String getJikwi() {
return jikwi;
}
public void setJikwi(String jikwi) {
this.jikwi = jikwi;
}
}
----------------------------------------------
//EmployeeDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class EmployeeDAO {
private Connection conn;
public void connect()
throws SQLException, ClassNotFoundException{
conn = DBConn.getConnection();
}
public void close()
throws SQLException {
DBConn.close();
conn = null;
}
public ArrayList<EmployeeDTO> cityList()
throws SQLException {
ArrayList<EmployeeDTO> arrayList
= new ArrayList<EmployeeDTO>();
String sql = String.format("SELECT city_id, city FROM city ORDER BY city_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
EmployeeDTO dto = new EmployeeDTO();
dto.setCity_id(rs.getInt("city_id"));
dto.setCity(rs.getString("city"));
arrayList.add(dto);
}
rs.close();
return arrayList;
}
public ArrayList<EmployeeDTO> buseoList()
throws SQLException {
ArrayList<EmployeeDTO> arrayList
= new ArrayList<EmployeeDTO>();
String sql = String.format("SELECT buseo_id, buseo FROM buseo ORDER BY buseo_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
EmployeeDTO dto = new EmployeeDTO();
dto.setBuseo_id(rs.getInt("buseo_id"));
dto.setBuseo(rs.getString("buseo"));
arrayList.add(dto);
}
rs.close();
return arrayList;
}
public ArrayList<EmployeeDTO> jikwiList()
throws SQLException {
ArrayList<EmployeeDTO> arrayList
= new ArrayList<EmployeeDTO>();
String sql = String.format("SELECT jikwi_id, jikwi FROM jikwi ORDER BY jikwi_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
EmployeeDTO dto = new EmployeeDTO();
dto.setJikwi_id(rs.getInt("jikwi_id"));
dto.setJikwi(rs.getString("jikwi"));
arrayList.add(dto);
}
rs.close();
return arrayList;
}
public int minBasicPay(int jikwi_id)
throws SQLException {
int result=0;
String sql = String.format("SELECT min_basicpay FROM jikwi WHERE jikwi_id = %d", jikwi_id);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()){
result = rs.getInt("min_basicpay");
}
rs.close();
return result;
}
public ArrayList<EmployeeDTO> lists(String orders)
throws SQLException {
ArrayList<EmployeeDTO> arrayList
= new ArrayList<EmployeeDTO>();
String sql = String.format("SELECT emp_id, name, ssn, TO_CHAR(ibsadate, 'YYYY-MM-DD') AS ibsadate, city_id, city, tel, buseo_id, buseo, jikwi_id, jikwi, basicpay, sudang, pay FROM empView %s", orders);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
EmployeeDTO dto = new EmployeeDTO();
dto.setEmp_id(rs.getInt("emp_id"));
dto.setName(rs.getString("name"));
dto.setSsn(rs.getString("ssn"));
dto.setIbsadate(rs.getString("ibsadate"));
//dto.setCity_id(rs.getInt("city_id"));
dto.setCity(rs.getString("city"));
dto.setTel(rs.getString("tel"));
//dto.setBuseo_id(rs.getInt("buseo_id"));
dto.setBuseo(rs.getString("buseo"));
//dto.setJikwi_id(rs.getInt("jikwi_id"));
dto.setJikwi(rs.getString("jikwi"));
dto.setBasicpay(rs.getInt("basicpay"));
dto.setSudang(rs.getInt("sudang"));
dto.setPay(rs.getInt("pay"));
arrayList.add(dto);
}
rs.close();
return arrayList;
}
public ArrayList<EmployeeDTO> empLists(String orders)
throws SQLException {
ArrayList<EmployeeDTO> arrayList
= new ArrayList<EmployeeDTO>();
String sql = String.format("SELECT emp_id, name, TO_CHAR(ibsadate, 'YYYY-MM-DD') AS ibsadate, city_id, city, tel, buseo_id, buseo, jikwi_id, jikwi FROM employeeView %s", orders);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
EmployeeDTO dto = new EmployeeDTO();
dto.setEmp_id(rs.getInt("emp_id"));
dto.setName(rs.getString("name"));
dto.setIbsadate(rs.getString("ibsadate"));
//dto.setCity_id(rs.getInt("city_id"));
dto.setCity(rs.getString("city"));
dto.setTel(rs.getString("tel"));
//dto.setBuseo_id(rs.getInt("buseo_id"));
dto.setBuseo(rs.getString("buseo"));
//dto.setJikwi_id(rs.getInt("jikwi_id"));
dto.setJikwi(rs.getString("jikwi"));
arrayList.add(dto);
}
rs.close();
return arrayList;
}
public int count()
throws SQLException {
int result = 0;
String sql = String.format("SELECT COUNT(*) AS count FROM emp");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
result = rs.getInt("count");
}
rs.close();
return result;
}
public int add(EmployeeDTO dto)
throws SQLException {
int result =0;
String sql = String.format("INSERT INTO emp (emp_id, name, ssn, ibsadate, city_id, tel, buseo_id, jikwi_id, basicpay, sudang) VALUES (empSeq.nextval, '%s', '%s', '%s', %d, '%s', %d, %d, %d, %d)"
, dto.getName()
, dto.getSsn()
, dto.getIbsadate()
, dto.getCity_id()
, dto.getTel()
, dto.getBuseo_id()
, dto.getJikwi_id()
, dto.getBasicpay()
, dto.getSudang());
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int count(String wheres)
throws SQLException {
int result = 0;
String sql = String.format("SELECT COUNT(*) AS count FROM empView %s", wheres);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
result = rs.getInt("count");
}
rs.close();
return result;
}
public ArrayList<EmployeeDTO> searchLists(String wheres, String orders)
throws SQLException {
ArrayList<EmployeeDTO> arrayList
= new ArrayList<EmployeeDTO>();
String sql = String.format("SELECT emp_id, name, ssn, TO_CHAR(ibsadate, 'YYYY-MM-DD') AS ibsadate, city_id, city, tel, buseo_id, buseo, jikwi_id, jikwi, basicpay, sudang, pay FROM empView %s %s", wheres, orders);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
EmployeeDTO dto = new EmployeeDTO();
dto.setEmp_id(rs.getInt("emp_id"));
dto.setName(rs.getString("name"));
dto.setSsn(rs.getString("ssn"));
dto.setIbsadate(rs.getString("ibsadate"));
dto.setCity_id(rs.getInt("city_id"));
dto.setCity(rs.getString("city"));
dto.setTel(rs.getString("tel"));
dto.setBuseo_id(rs.getInt("buseo_id"));
dto.setBuseo(rs.getString("buseo"));
dto.setJikwi_id(rs.getInt("jikwi_id"));
dto.setJikwi(rs.getString("jikwi"));
dto.setBasicpay(rs.getInt("basicpay"));
dto.setSudang(rs.getInt("sudang"));
dto.setPay(rs.getInt("pay"));
arrayList.add(dto);
}
rs.close();
return arrayList;
}
public ArrayList<EmployeeDTO> empSearchLists(String wheres, String orders)
throws SQLException {
ArrayList<EmployeeDTO> arrayList
= new ArrayList<EmployeeDTO>();
String sql = String.format("SELECT emp_id, name, TO_CHAR(ibsadate, 'YYYY-MM-DD') AS ibsadate, city_id, city, tel, buseo_id, buseo, jikwi_id, jikwi FROM employeeView %s %s", wheres, orders);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
EmployeeDTO dto = new EmployeeDTO();
dto.setEmp_id(rs.getInt("emp_id"));
dto.setName(rs.getString("name"));
dto.setIbsadate(rs.getString("ibsadate"));
dto.setCity_id(rs.getInt("city_id"));
dto.setCity(rs.getString("city"));
dto.setTel(rs.getString("tel"));
dto.setBuseo_id(rs.getInt("buseo_id"));
dto.setBuseo(rs.getString("buseo"));
dto.setJikwi_id(rs.getInt("jikwi_id"));
dto.setJikwi(rs.getString("jikwi"));
arrayList.add(dto);
}
rs.close();
return arrayList;
}
public int modify(EmployeeDTO dto)
throws SQLException {
int result = 0;
String sql = String.format("UPDATE emp SET name='%s', ssn='%s', ibsadate='%s', city_id=%d, tel='%s', buseo_id=%d, jikwi_id=%d, basicpay=%d, sudang=%d WHERE emp_id=%d", dto.getName(), dto.getSsn(), dto.getIbsadate(), dto.getCity_id(), dto.getTel(), dto.getBuseo_id(), dto.getJikwi_id(), dto.getBasicpay(), dto.getSudang(), dto.getEmp_id());
System.out.println(sql);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int remove(int emp_id)
throws SQLException {
int result = 0;
String sql = String.format("DELETE emp WHERE emp_id=%d", emp_id);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int loginEmp(String id, String pw)
throws SQLException {
int result = 0;
String sql = String.format("SELECT COUNT(*) AS count FROM emp WHERE name='%s' AND SUBSTR(ssn, 8, 7)='%s'", id, pw);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
result = rs.getInt("count");
}
rs.close();
return result;
}
public int loginAdmin(String id, String pw)
throws SQLException {
int result = 0;
String sql = String.format("SELECT COUNT(*) AS count FROM empAdmin WHERE id='%s' AND pw=encrypt('%s', '%s')", id, pw, id);
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
result = rs.getInt("count");
}
rs.close();
return result;
}
}
----------------------------------------------
//CityDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class CityDAO {
Connection conn;
public void connect()
throws SQLException, ClassNotFoundException {
conn = DBConn.getConnection();
}
public void close()
throws SQLException {
DBConn.close();
conn = null;
}
public int add(String city)
throws SQLException {
int result = 0;
String sql = String.format("INSERT INTO city (city_id, city) VALUES (citySeq.nextval, '%s')", city);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public ArrayList<CityDTO> lists()
throws SQLException {
ArrayList<CityDTO> arrayList
= new ArrayList<CityDTO>();
String sql = String.format("SELECT city_id, city FROM city ORDER BY city_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int city_id = rs.getInt("city_id");
String city = rs.getString("city");
CityDTO dto = new CityDTO();
dto.setCity_id(city_id);
dto.setCity(city);
arrayList.add(dto);
}
rs.close();
return arrayList;
}
/*public ArrayList<CityDTO> search(String key, String value)
throws SQLException {
ArrayList<CityDTO> arrayList
= new ArrayList<CityDTO>();
return arrayList;
}*/
public int modify(CityDTO dto)
throws SQLException {
int result = 0;
String sql = String.format("UPDATE city SET city='%s' WHERE city_id=%d", dto.getCity(), dto.getCity_id());
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int remove(int city_id)
throws SQLException {
int result = 0;
String sql = String.format("DELETE city WHERE city_id=%d", city_id);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
}
----------------------------------------------
//BuseoDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class BuseoDAO {
Connection conn;
public void connect()
throws SQLException, ClassNotFoundException {
conn = DBConn.getConnection();
}
public void close()
throws SQLException {
DBConn.close();
conn = null;
}
public int add(String buseo)
throws SQLException {
int result = 0;
String sql = String.format("INSERT INTO buseo (buseo_id, buseo) VALUES (buseoSeq.nextval, '%s')", buseo);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public ArrayList<BuseoDTO> lists()
throws SQLException {
ArrayList<BuseoDTO> arrayList
= new ArrayList<BuseoDTO>();
String sql = String.format("SELECT buseo_id, buseo FROM buseo ORDER BY buseo_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int buseo_id = rs.getInt("buseo_id");
String buseo = rs.getString("buseo");
BuseoDTO dto = new BuseoDTO();
dto.setBuseo_id(buseo_id);
dto.setBuseo(buseo);
arrayList.add(dto);
}
rs.close();
return arrayList;
}
/*public ArrayList<BuseoDTO> search(String key, String value)
throws SQLException {
ArrayList<BuseoDTO> arrayList
= new ArrayList<BuseoDTO>();
return arrayList;
}*/
public int modify(BuseoDTO dto)
throws SQLException {
int result = 0;
String sql = String.format("UPDATE buseo SET buseo='%s' WHERE buseo_id=%d", dto.getBuseo(), dto.getBuseo_id());
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int remove(int buseo_id)
throws SQLException {
int result = 0;
String sql = String.format("DELETE buseo WHERE buseo_id=%d", buseo_id);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
}
----------------------------------------------
//JikwiDAO.java
package com.test;
import java.sql.*;
import java.util.*;
public class JikwiDAO {
Connection conn;
public void connect()
throws SQLException, ClassNotFoundException {
conn = DBConn.getConnection();
}
public void close()
throws SQLException {
DBConn.close();
conn = null;
}
public int add(String jikwi)
throws SQLException {
int result = 0;
String sql = String.format("INSERT INTO jikwi (jikwi_id, jikwi) VALUES (jikwiSeq.nextval, '%s')", jikwi);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public ArrayList<JikwiDTO> lists()
throws SQLException {
ArrayList<JikwiDTO> arrayList
= new ArrayList<JikwiDTO>();
String sql = String.format("SELECT jikwi_id, jikwi FROM jikwi ORDER BY jikwi_id");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(sql);
while(rs.next()) {
int jikwi_id = rs.getInt("jikwi_id");
String jikwi = rs.getString("jikwi");
JikwiDTO dto = new JikwiDTO();
dto.setJikwi_id(jikwi_id);
dto.setJikwi(jikwi);
arrayList.add(dto);
}
rs.close();
return arrayList;
}
/*public ArrayList<JikwiDTO> search(String key, String value)
throws SQLException {
ArrayList<JikwiDTO> arrayList
= new ArrayList<JikwiDTO>();
return arrayList;
}*/
public int modify(JikwiDTO dto)
throws SQLException {
int result = 0;
String sql = String.format("UPDATE jikwi SET jikwi='%s' WHERE jikwi_id=%d", dto.getJikwi(), dto.getJikwi_id());
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
public int remove(int jikwi_id)
throws SQLException {
int result = 0;
String sql = String.format("DELETE jikwi WHERE jikwi_id=%d", jikwi_id);
Statement stmt = conn.createStatement();
result = stmt.executeUpdate(sql);
return result;
}
}
----------------------------------------------
//BasicStyle.css -> CSS 스타일 시트 전용.
@CHARSET "EUC-KR";
body {
color:#2f3743;
}
a { /* a 태그에만 적용 */
text-decoration: none; /* 글자의 장식 지정 없앰 */
color:gray; /* 글자색 */
}
a:hover { /* a 태그에 커서가 올려져 있을때만 적용 */
text-decoration: underline; /* 밑줄 장식 지정 */
color:red;
}
table.style00 td, table.style00 th
{
padding: 3px;
border-right-style: solid;
border-bottom-style: solid;
border-width: 1px;
border-color: #6980b8;
}
table.style00 td:hover
{
background-color:#d2d2d2;
}
.style1 { /* class 속성의 값이 style1인 경우만 적용 */
text-align:center; /* 가운데 정렬 */
}
.style2 { /* class 속성의 값이 style2인 경우만 적용 */
text-align:right; /* 오른쪽 정렬 */
}
#result {
overflow:auto; /* DIV 태그 내부에 스크롤 생성 */
height:300px;
}
----------------------------------------------
//LoginForm.jsp -> 로그인 페이지. ID, PW 확인 및 세션 처리
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*" %>
<%
String result = "false";
request.setCharacterEncoding("euc-kr");
String group = request.getParameter("group");
String id = request.getParameter("id");
String pw = request.getParameter("pw");
if (id != null && pw != null) {
EmployeeDAO dao = new EmployeeDAO();
try {
dao.connect();
//ID, PW 검사 과정
int count = 0;
if (group.equals("admin")) {
count = dao.loginAdmin(id, pw);
} else if (group.equals("emp")) {
count = dao.loginEmp(id, pw);
}
//결과는 두 가지
if (count == 1) {
//로그인 성공 -> 세션 객체 생성 -> 화면 전환
//세션
//-> 로그인 성공 여부 확인용
//-> 직원 확인용
//-> 관리자 확인용
session.setAttribute("loginCheck", "true");
if (group.equals("admin")) {
session.setAttribute("admin", id);
} else if (group.equals("emp")) {
session.setAttribute("emp", id);
}
response.sendRedirect("Employee_Select.jsp");
} else {
//로그인 실패 -> 현재 화면에서 에러 메시지 출력
result = "true";
}
}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>
<script type="text/javascript">
function myFunc(obj) {
//문제) 데이터 검사 과정 추가할 것.
//데이터 전송
obj.form.submit();
}
function msg() {
if (<%=result%>) {
alert("아이디 또는 패스워드가 틀렸습니다.");
}
}
</script>
</head>
<body onload="msg()">
<div align="center" style="padding-top:100px;">
<form method="post">
<h1>직원관리 (JSP버전)</h1>
<input type="radio"
name="group" value="admin"> 관리자
<input type="radio"
name="group"
checked="checked"
value="emp"> 일반직원
<table class="style4">
<tr>
<td valign="middle">
<img src="img/img_login.gif">
</td>
<td>
<table>
<tr>
<td>ID</td>
<td><input type="text" style="width:150px;" id="id" name="id"></td>
</tr>
<tr>
<td>PW</td>
<td><input type="password" style="width:150px;" id="pw" name="pw"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="button" value="로그인"
onclick="myFunc(this)">
<br>
<span id="msg" style="color:red; display:none;">에러메시지 출력 영역</span>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
----------------------------------------------
//Logout.jsp -> 로그아웃 액션 처리.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
//세션 개별 소멸
//session.removeAttribute("loginCheck");
//session.removeAttribute("admin");
//session.removeAttribute("emp");
//세션 전체 소멸
session.invalidate();
response.sendRedirect("LoginForm.jsp");
%>
----------------------------------------------
//MainMenu.jsp -> 메인 메뉴 전용.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<div>
[<a href="Employee_Select.jsp">직원출력</a>]
[<a href="Employee_Search.jsp">직원검색</a>]
<c:if test="${!empty sessionScope.admin}">
[<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>]
</c:if>
[<a href="Logout.jsp">로그아웃</a>]
</div>
<hr>
----------------------------------------------
//City.jsp -> 지역관리. 입력, 출력, 수정, 삭제 기능.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
//관리자 확인
if (session.getAttribute("loginCheck") == null || session.getAttribute("admin") == null) {
response.sendRedirect("Logout.jsp");
}
request.setCharacterEncoding("euc-kr");
String num = request.getParameter("num");
String name = request.getParameter("name");
String key = request.getParameter("key"); //액션 구분용 값
StringBuilder str = new StringBuilder();
CityDAO dao = new CityDAO();
try {
dao.connect();
if (key != null && key.equals("insert")) {
dao.add(name);
}
if (key != null && key.equals("update")) {
//수정 메소드 호출
CityDTO dto = new CityDTO();
dto.setCity_id(Integer.parseInt(num));
dto.setCity(name);
dao.modify(dto);
}
if (key != null && key.equals("delete")) {
//삭제 메소드 호출
dao.remove(Integer.parseInt(num));
}
for (CityDTO dto : dao.lists()) {
str.append(String.format("<tr>"));
str.append(String.format("<td class=\"style1\">%d</td>", dto.getCity_id()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getCity()));
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 cityForm(status) {
var myForm = document.getElementById("myForm");
var num = document.getElementById("num");
var name = document.getElementById("name");
var key = document.getElementById("key");
var numMsg = document.getElementById("numMsg");
var nameMsg = document.getElementById("nameMsg");
numMsg.style.display = "none";
nameMsg.style.display = "none";
if (status == "insert") {
//이름 검사 (공백)
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
if (status == "delete") {
//번호 검사 (공백, 숫자)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
}
if (status == "update") {
//번호 검사 (공백, 숫자)
//이름 검사 (공백)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
key.value = status;
myForm.submit();
}
</script>
</head>
<body>
<div>
<div>
<h2>직원관리_지역관리</h2>
<c:import url="MainMenu.jsp"></c:import>
</div>
<div>
<form method="post" id="myForm">
<%-- 추가, 수정, 삭제 구분용 값을 서버로 전송 --%>
<input type="hidden" id="key" name="key" value="">
지역번호<input type="text" id="num" name="num"><span id="numMsg" style="color:red; display:none;">지역번호를 입력해야 합니다.</span><br>
지역이름<input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">지역이름을 입력해야 합니다.</span><br>
[<a href="">전체출력</a>]
[<a href="javascript:cityForm('insert')">지역추가</a>]
[<a href="javascript:cityForm('update')">지역수정</a>]
[<a href="javascript:cityForm('delete')">지역삭제</a>]<br><br>
</form>
<table style="width:400px;" class="style00">
<tbody>
<tr>
<th>번호</th><th>지역</th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</body>
</html>
----------------------------------------------
//Buseo.jsp -> 부서관리. 입력, 출력, 수정, 삭제 기능.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
//관리자 확인
if (session.getAttribute("loginCheck") == null || session.getAttribute("admin") == null) {
response.sendRedirect("Logout.jsp");
}
request.setCharacterEncoding("euc-kr");
String num = request.getParameter("num");
String name = request.getParameter("name");
String key = request.getParameter("key"); //액션 구분용 값
StringBuilder str = new StringBuilder();
BuseoDAO dao = new BuseoDAO();
try {
dao.connect();
if (key != null && key.equals("insert")) {
dao.add(name);
}
if (key != null && key.equals("update")) {
//수정 메소드 호출
BuseoDTO dto = new BuseoDTO();
dto.setBuseo_id(Integer.parseInt(num));
dto.setBuseo(name);
dao.modify(dto);
}
if (key != null && key.equals("delete")) {
//삭제 메소드 호출
dao.remove(Integer.parseInt(num));
}
for (BuseoDTO dto : dao.lists()) {
str.append(String.format("<tr>"));
str.append(String.format("<td class=\"style1\">%d</td>", dto.getBuseo_id()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getBuseo()));
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 buseoForm(status) {
var myForm = document.getElementById("myForm");
var num = document.getElementById("num");
var name = document.getElementById("name");
var key = document.getElementById("key");
var numMsg = document.getElementById("numMsg");
var nameMsg = document.getElementById("nameMsg");
numMsg.style.display = "none";
nameMsg.style.display = "none";
if (status == "insert") {
//이름 검사 (공백)
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
if (status == "delete") {
//번호 검사 (공백, 숫자)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
}
if (status == "update") {
//번호 검사 (공백, 숫자)
//이름 검사 (공백)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
key.value = status;
myForm.submit();
}
</script>
</head>
<body>
<div>
<div>
<h2>직원관리_부서관리</h2>
<c:import url="MainMenu.jsp"></c:import>
</div>
<div>
<form method="post" id="myForm">
<%-- 추가, 수정, 삭제 구분용 값을 서버로 전송 --%>
<input type="hidden" id="key" name="key" value="">
부서번호<input type="text" id="num" name="num"><span id="numMsg" style="color:red; display:none;">부서번호를 입력해야 합니다.</span><br>
부서이름<input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">부서이름을 입력해야 합니다.</span><br>
[<a href="">전체출력</a>]
[<a href="javascript:buseoForm('insert')">부서추가</a>]
[<a href="javascript:buseoForm('update')">부서수정</a>]
[<a href="javascript:buseoForm('delete')">부서삭제</a>]<br><br>
</form>
<table style="width:400px;" class="style00">
<tbody>
<tr>
<th>번호</th><th>부서</th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</body>
</html>
----------------------------------------------
//Jikwi.jsp -> 직위관리. 입력, 출력, 수정, 삭제 기능.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
//관리자 확인
if (session.getAttribute("loginCheck") == null || session.getAttribute("admin") == null) {
response.sendRedirect("Logout.jsp");
}
request.setCharacterEncoding("euc-kr");
String num = request.getParameter("num");
String name = request.getParameter("name");
String key = request.getParameter("key"); //액션 구분용 값
StringBuilder str = new StringBuilder();
JikwiDAO dao = new JikwiDAO();
try {
dao.connect();
if (key != null && key.equals("insert")) {
dao.add(name);
}
if (key != null && key.equals("update")) {
//수정 메소드 호출
JikwiDTO dto = new JikwiDTO();
dto.setJikwi_id(Integer.parseInt(num));
dto.setJikwi(name);
dao.modify(dto);
}
if (key != null && key.equals("delete")) {
//삭제 메소드 호출
dao.remove(Integer.parseInt(num));
}
for (JikwiDTO dto : dao.lists()) {
str.append(String.format("<tr>"));
str.append(String.format("<td class=\"style1\">%d</td>", dto.getJikwi_id()));
str.append(String.format("<td class=\"style1\">%s</td>", dto.getJikwi()));
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 jikwiForm(status) {
var myForm = document.getElementById("myForm");
var num = document.getElementById("num");
var name = document.getElementById("name");
var key = document.getElementById("key");
var numMsg = document.getElementById("numMsg");
var nameMsg = document.getElementById("nameMsg");
numMsg.style.display = "none";
nameMsg.style.display = "none";
if (status == "insert") {
//이름 검사 (공백)
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
if (status == "delete") {
//번호 검사 (공백, 숫자)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
}
if (status == "update") {
//번호 검사 (공백, 숫자)
//이름 검사 (공백)
if(num.value == "" || num.value.match(/[^0-9]/)) {
numMsg.style.display = "inline";
return;
}
if(name.value == "") {
nameMsg.style.display = "inline";
return;
}
}
key.value = status;
myForm.submit();
}
</script>
</head>
<body>
<div>
<div>
<h2>직원관리_직위관리</h2>
<c:import url="MainMenu.jsp"></c:import>
</div>
<div>
<form method="post" id="myForm">
<%-- 추가, 수정, 삭제 구분용 값을 서버로 전송 --%>
<input type="hidden" id="key" name="key" value="">
직위번호<input type="text" id="num" name="num"><span id="numMsg" style="color:red; display:none;">직위번호를 입력해야 합니다.</span><br>
직위이름<input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">직위이름을 입력해야 합니다.</span><br>
[<a href="">전체출력</a>]
[<a href="javascript:jikwiForm('insert')">직위추가</a>]
[<a href="javascript:jikwiForm('update')">직위수정</a>]
[<a href="javascript:jikwiForm('delete')">직위삭제</a>]<br><br>
</form>
<table style="width:400px;" class="style00">
<tbody>
<tr>
<th>번호</th><th>직위</th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</body>
</html>
----------------------------------------------
//Employee_Select.jsp -> 직원관리. 출력 기능.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
if (session.getAttribute("loginCheck") == null) {
response.sendRedirect("LoginForm.jsp");
}
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 = "Employee_Select.jsp?order=emp_id&direction=desc";
} else {
urlEmp_id = "Employee_Select.jsp?order=emp_id&direction=asc";
}
if (order.equals("name") && direction.equals("asc")) {
urlName = "Employee_Select.jsp?order=name&direction=desc";
} else {
urlName = "Employee_Select.jsp?order=name&direction=asc";
}
if (order.equals("ssn") && direction.equals("asc")) {
urlSsn = "Employee_Select.jsp?order=ssn&direction=desc";
} else {
urlSsn = "Employee_Select.jsp?order=ssn&direction=asc";
}
if (order.equals("ibsadate") && direction.equals("asc")) {
urlIbsadate = "Employee_Select.jsp?order=ibsadate&direction=desc";
} else {
urlIbsadate = "Employee_Select.jsp?order=ibsadate&direction=asc";
}
if (order.equals("city") && direction.equals("asc")) {
urlCity = "Employee_Select.jsp?order=city&direction=desc";
} else {
urlCity = "Employee_Select.jsp?order=city&direction=asc";
}
if (order.equals("tel") && direction.equals("asc")) {
urlTel = "Employee_Select.jsp?order=tel&direction=desc";
} else {
urlTel = "Employee_Select.jsp?order=tel&direction=asc";
}
if (order.equals("buseo") && direction.equals("asc")) {
urlBuseo = "Employee_Select.jsp?order=buseo&direction=desc";
} else {
urlBuseo = "Employee_Select.jsp?order=buseo&direction=asc";
}
if (order.equals("jikwi") && direction.equals("asc")) {
urlJikwi = "Employee_Select.jsp?order=jikwi&direction=desc";
} else {
urlJikwi = "Employee_Select.jsp?order=jikwi&direction=asc";
}
if (order.equals("basicpay") && direction.equals("asc")) {
urlBasicpay = "Employee_Select.jsp?order=basicpay&direction=desc";
} else {
urlBasicpay = "Employee_Select.jsp?order=basicpay&direction=asc";
}
if (order.equals("sudang") && direction.equals("asc")) {
urlSudang = "Employee_Select.jsp?order=sudang&direction=desc";
} else {
urlSudang = "Employee_Select.jsp?order=sudang&direction=asc";
}
if (order.equals("pay") && direction.equals("asc")) {
urlPay = "Employee_Select.jsp?order=pay&direction=desc";
} else {
urlPay = "Employee_Select.jsp?order=pay&direction=asc";
}
StringBuilder str = new StringBuilder();
String count = "0";
EmployeeDAO dao = new EmployeeDAO();
try {
dao.connect();
count = String.valueOf(dao.count());
String orders = String.format("ORDER BY %s %s", order, direction);
if (session.getAttribute("admin") != null) {
for (EmployeeDTO dto : dao.lists(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>"));
}
} else if (session.getAttribute("emp") != null) {
for (EmployeeDTO dto : dao.empLists(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.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("</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">
</head>
<body>
<div>
<div>
<h2>직원관리_직원출력[<%=session.getAttribute("emp")%>]</h2>
<c:import url="MainMenu.jsp"></c:import>
</div>
<div>
<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>
<c:if test="${!empty sessionScope.admin}">
<th><a href="<%=urlSsn%>">주민번호</a></th>
</c:if>
<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>
<c:if test="${!empty sessionScope.admin}">
<th><a href="<%=urlBasicpay%>">기본급</a></th>
<th><a href="<%=urlSudang%>">수당</a></th>
<th><a href="<%=urlPay%>">급여</a></th>
</c:if>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
----------------------------------------------
//Employee_Search.jsp -> 직원관리. 검색 기능.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
if (session.getAttribute("loginCheck") == null) {
response.sendRedirect("LoginForm.jsp");
}
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));
if (session.getAttribute("admin") != null) {
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>"));
}
} else if (session.getAttribute("emp") != null) {
for (EmployeeDTO dto : dao.empSearchLists(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.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("</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>직원관리_직원검색[<%=session.getAttribute("emp")%>]</h2>
<c:import url="MainMenu.jsp"></c:import>
</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>
<c:if test="${!empty sessionScope.admin}">
<th><a href="<%=urlSsn%>">주민번호</a></th>
</c:if>
<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>
<c:if test="${!empty sessionScope.admin}">
<th><a href="<%=urlBasicpay%>">기본급</a></th>
<th><a href="<%=urlSudang%>">수당</a></th>
<th><a href="<%=urlPay%>">급여</a></th>
</c:if>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>
----------------------------------------------
//MinBasicPayCheck.jsp -> 직원관리 입력 폼에서 직위 선택시 최소기본급을 리턴하는 전용 페이지. Ajax 요청 기능.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*" %>
<%
String jikwi_id = request.getParameter("jikwi_id");
EmployeeDAO dao = new EmployeeDAO();
int minBasicPay = 0;
try {
dao.connect();
minBasicPay = dao.minBasicPay(Integer.parseInt(jikwi_id));
}catch(Exception e) {
System.out.println(e.toString());
}finally{
dao.close();
}
out.write(String.format("%,d", minBasicPay));
%>
----------------------------------------------
//Employee_InsertForm.jsp -> 직원관리. 입력 폼 화면 구성. Ajax 요청 기능. jQuery 달력 기능.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
//관리자 확인
if (session.getAttribute("loginCheck") == null || session.getAttribute("admin") == null) {
response.sendRedirect("Logout.jsp");
}
String insertOK = request.getParameter("insertOK");
if (insertOK == null) {
insertOK = "false";
}
StringBuilder cityLists = new StringBuilder();
StringBuilder buseoLists = new StringBuilder();
StringBuilder jikwiLists = new StringBuilder();
EmployeeDAO dao = new EmployeeDAO();
try {
dao.connect();
for (EmployeeDTO dto : dao.cityList()) {
cityLists.append(String.format("<option value=\"%d\">%s</option>", dto.getCity_id(), dto.getCity()));
}
for (EmployeeDTO dto : dao.buseoList()) {
buseoLists.append(String.format("<option value=\"%d\">%s</option>", dto.getBuseo_id(), dto.getBuseo()));
}
for (EmployeeDTO dto : dao.jikwiList()) {
jikwiLists.append(String.format("<option value=\"%d\">%s</option>", dto.getJikwi_id(), dto.getJikwi()));
}
}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">
<link rel="stylesheet"
href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<script>
$(function() {
$("#ibsadate").datepicker({dateFormat:"yy-mm-dd"});
});
</script>
<script type="text/javascript">
//Ajax 전역 변수
var xmlReq;
function myFunc() {
var myForm = document.getElementById("myForm");
//문제) 데이터 검사 과정 추가할 것.
var name = document.getElementById("name");
var ssn = document.getElementById("ssn");
var ibsadate = document.getElementById("ibsadate");
var tel = document.getElementById("tel");
var basicpay = document.getElementById("basicpay");
var sudang = document.getElementById("sudang");
var nameMsg = document.getElementById("nameMsg");
var ssnMsg = document.getElementById("ssnMsg");
var ibsadateMsg = document.getElementById("ibsadateMsg");
var telMsg = document.getElementById("telMsg");
var basicpayMsg = document.getElementById("basicpayMsg");
var sudangMsg = document.getElementById("sudangMsg");
nameMsg.style.display = "none";
ssnMsg.style.display = "none";
ibsadateMsg.style.display = "none";
telMsg.style.display = "none";
basicpayMsg.style.display = "none";
sudangMsg.style.display = "none";
//빈칸 검사
if(name.value == ""){
nameMsg.style.display = "inline";
return;
}
if(ssn.value == ""){
ssnMsg.style.display = "inline";
return;
}
if(ibsadate.value == ""){
ibsadateMsg.style.display = "inline";
return;
}
if(tel.value == ""){
telMsg.style.display = "inline";
return;
}
if(basicpay.value == ""){
basicpayMsg.style.display = "inline";
return;
}
//숫자 검사
if (basicpay.value.match(/[^0-9]/)){
basicpayMsg.style.display = "inline";
return;
}
if(sudang.value == ""){
sudangMsg.style.display = "inline";
return;
}
if (sudang.value.match(/[^0-9]/)){
sudangMsg.style.display = "inline";
return;
}
//데이터 전송
myForm.submit();
}
function msg() {
if (<%=insertOK%>) {
alert("입력이 완료되었습니다.");
}
}
function minBasicPayCheck(obj) {
var jikwi_id = obj.options[obj.selectedIndex];
xmlReq = new XMLHttpRequest(); //IE7.0 이상
var url = "MinBasicPayCheck.jsp";
var postString = "jikwi_id="+jikwi_id.value;
xmlReq.onreadystatechange = callBack;
xmlReq.open("POST", url, true);
xmlReq.setRequestHeader("Content-Type"
, "application/x-www-form-urlencoded; charset=euc-kr");
xmlReq.send(postString);
}
function callBack() {
if (xmlReq.readyState == 4) {
if (xmlReq.status == 200) {
printData();
}
}
}
function printData() {
var result = xmlReq.responseText;
var minBasicPay = document.getElementById("minBasicPay");
minBasicPay.innerHTML = result;
}
</script>
</head>
<body onload="msg()">
<div>
<div>
<h2>직원관리_직원입력</h2>
<c:import url="MainMenu.jsp"></c:import>
</div>
<div>
<form action="Employee_Insert.jsp" method="post" id="myForm">
<table>
<tr>
<td>이름</td>
<td><input type="text" id="name" name="name"><span id="nameMsg" style="color:red; display:none;">이름를 채워야 합니다.</span></td>
</tr>
<tr>
<td>주민번호(YYMMDD-NNNNNNN)</td>
<td><input type="text" id="ssn" name="ssn"><span id="ssnMsg" style="color:red; display:none;">주민번호를 채워야 합니다.</span></td>
</tr>
<tr>
<td>입사일(YYYY-MM-DD)</td>
<td><input type="text" id="ibsadate" name="ibsadate"><span id="ibsadateMsg" style="color:red; display:none;">입사일을 채워야 합니다.</span></td>
</tr>
<tr>
<td>지역</td>
<td><select style="width:154px;" id="city_id" name="city_id"><%=cityLists%></select></td>
</tr>
<tr>
<td>전화번호</td>
<td><input type="text" id="tel" name="tel"><span id="telMsg" style="color:red; display:none;">전화번호를 채워야 합니다.</span></td>
</tr>
<tr>
<td>부서</td>
<td><select style="width:154px;" id="buseo_id" name="buseo_id"><%=buseoLists%></select></td>
</tr>
<tr>
<td>직위</td>
<td><select style="width:154px;" id="jikwi_id" name="jikwi_id" onchange="minBasicPayCheck(this)"><%=jikwiLists%></select></td>
</tr>
<tr>
<td>기본급(최소 <span id="minBasicPay">????</span> 이상)</td>
<td><input type="text" id="basicpay" name="basicpay"><span id="basicpayMsg" style="color:red; display:none;">기본급은 숫자로만 채워야 합니다.</span></td>
</tr>
<tr>
<td>수당</td>
<td><input type="text" id="sudang" name="sudang"><span id="sudangMsg" style="color:red; display:none;">수당은 숫자로만 채워야 합니다.</span></td>
</tr>
</table>
[<a href="javascript:myFunc()">입력</a>]
</form>
</div>
</div>
</body>
</html>
----------------------------------------------
//Employee_Insert.jsp -> 직원관리. 입력 액션 처리.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*"%>
<%
//문제) 직원 입력 과정 추가할 것.
//한글 인코딩 처리 필요
//데이터 수신
//DAO 객체 생성
//데이터베이스 연결
//DTO 객체 생성
//INSERT 쿼리 메소드 호출
request.setCharacterEncoding("euc-kr");
String name = request.getParameter("name");
String ssn = request.getParameter("ssn");
String ibsadate = request.getParameter("ibsadate");
String city_id = request.getParameter("city_id");
String tel = request.getParameter("tel");
String buseo_id = request.getParameter("buseo_id");
String jikwi_id = request.getParameter("jikwi_id");
String basicpay = request.getParameter("basicpay");
String sudang = request.getParameter("sudang");
EmployeeDAO dao = new EmployeeDAO();
try {
dao.connect();
EmployeeDTO dto = new EmployeeDTO();
dto.setName(name);
dto.setSsn(ssn);
dto.setIbsadate(ibsadate);
dto.setCity_id(Integer.parseInt(city_id));
dto.setTel(tel);
dto.setBuseo_id(Integer.parseInt(buseo_id));
dto.setJikwi_id(Integer.parseInt(jikwi_id));
dto.setBasicpay(Integer.parseInt(basicpay));
dto.setSudang(Integer.parseInt(sudang));
dao.add(dto);
}catch(Exception e){
System.out.println(e.toString());
}finally{
dao.close();
}
//입력 과정이 모두 끝나면 입력 폼 페이지로 돌아가도록 함.
String url = String.format("Employee_InsertForm.jsp?insertOK=true");
response.sendRedirect(url);
%>
----------------------------------------------
//Employee_UpdateForm.jsp -> 직원관리. 수정 폼 화면 구성.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
//관리자 확인
if (session.getAttribute("loginCheck") == null || session.getAttribute("admin") == null) {
response.sendRedirect("Logout.jsp");
}
String value = request.getParameter("value");
if (value == null) {
value = "";
}
EmployeeDAO dao = new EmployeeDAO();
String name = "";
String ssn = "";
String ibsadate = "";
String tel = "";
String basicpay = "";
String sudang = "";
int city_id = 0;
int buseo_id = 0;
int jikwi_id = 0;
StringBuilder cityLists = new StringBuilder();
StringBuilder buseoLists = new StringBuilder();
StringBuilder jikwiLists = new StringBuilder();
try {
dao.connect();
String wheres = String.format("WHERE emp_id='%s'", value);
String orders = "";
for (EmployeeDTO dto : dao.searchLists(wheres,orders)) {
name = dto.getName();
ssn = dto.getSsn();
ibsadate = dto.getIbsadate();
tel = dto.getTel();
basicpay = String.valueOf(dto.getBasicpay());
sudang = String.valueOf(dto.getSudang());
city_id = dto.getCity_id();
buseo_id = dto.getBuseo_id();
jikwi_id = dto.getJikwi_id();
}
for (EmployeeDTO dto : dao.cityList()) {
if (city_id == dto.getCity_id()) {
cityLists.append(String.format("<option value=\"%d\" selected=\"selected\">%s</option>", dto.getCity_id(), dto.getCity()));
} else {
cityLists.append(String.format("<option value=\"%d\">%s</option>", dto.getCity_id(), dto.getCity()));
}
}
for (EmployeeDTO dto : dao.buseoList()) {
if (buseo_id == dto.getBuseo_id()) {
buseoLists.append(String.format("<option value=\"%d\" selected=\"selected\">%s</option>", dto.getBuseo_id(), dto.getBuseo()));
} else {
buseoLists.append(String.format("<option value=\"%d\">%s</option>", dto.getBuseo_id(), dto.getBuseo()));
}
}
for (EmployeeDTO dto : dao.jikwiList()) {
if (jikwi_id == dto.getJikwi_id()) {
jikwiLists.append(String.format("<option value=\"%d\" selected=\"selected\">%s</option>", dto.getJikwi_id(), dto.getJikwi()));
} else {
jikwiLists.append(String.format("<option value=\"%d\">%s</option>", dto.getJikwi_id(), dto.getJikwi()));
}
}
}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");
//문제) 데이터 검사 과정 추가할 것.
var emp_id = document.getElementById("emp_id");
var searchValue = document.getElementById("value");
emp_id.value = searchValue.value;
//데이터 전송
myForm.submit();
}
//문제) 직위 변경시 최소 기본급 메시지 수정되는 부분 작성. Ajax.
</script>
</head>
<body>
<div>
<div>
<h2>직원관리_직원수정</h2>
<c:import url="MainMenu.jsp"></c:import>
</div>
<div>
<form method="get" id="myForm">
사번
<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>
<form action="Employee_Update.jsp" method="post" id="myForm">
<input type="hidden" id="emp_id" name="emp_id" value="">
<table>
<tr>
<td>이름</td>
<td><input type="text" id="name" name="name" value="<%=name%>"><span id="nameMsg" style="color:red; display:none;">이름를 채워야 합니다.</span></td>
</tr>
<tr>
<td>주민번호(YYMMDD-NNNNNNN)</td>
<td><input type="text" id="ssn" name="ssn" value="<%=ssn%>"><span id="ssnMsg" style="color:red; display:none;">주민번호를 채워야 합니다.</span></td>
</tr>
<tr>
<td>입사일(YYYY-MM-DD)</td>
<td><input type="text" id="ibsadate" name="ibsadate" value="<%=ibsadate%>"><span id="ibsadateMsg" style="color:red; display:none;">입사일을 채워야 합니다.</span></td>
</tr>
<tr>
<td>지역</td>
<td><select style="width:154px;" id="city_id" name="city_id"><%=cityLists%></select></td>
</tr>
<tr>
<td>전화번호</td>
<td><input type="text" id="tel" name="tel" value="<%=tel%>"><span id="telMsg" style="color:red; display:none;">전화번호를 채워야 합니다.</span></td>
</tr>
<tr>
<td>부서</td>
<td><select style="width:154px;" id="buseo_id" name="buseo_id"><%=buseoLists%></select></td>
</tr>
<tr>
<td>직위</td>
<td><select style="width:154px;" id="jikwi_id" name="jikwi_id" onchange="minBasicPayCheck(this)"><%=jikwiLists%></select></td>
</tr>
<tr>
<td>기본급(최소 <span id="minBasicPay">????</span> 이상)</td>
<td><input type="text" id="basicpay" name="basicpay" value="<%=basicpay%>"><span id="basicpayMsg" style="color:red; display:none;">기본급은 숫자로만 채워야 합니다.</span></td>
</tr>
<tr>
<td>수당</td>
<td><input type="text" id="sudang" name="sudang" value="<%=sudang%>"><span id="sudangMsg" style="color:red; display:none;">수당은 숫자로만 채워야 합니다.</span></td>
</tr>
</table>
[<a href="javascript:myFunc()">수정</a>]
</form>
</div>
</div>
</body>
</html>
----------------------------------------------
//Employee_Update.jsp -> 직원관리. 수정 액션 처리.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
//한글 인코딩 처리
//데이터 수신
//emp_id, name, ...., sudang
//EmployeeDAO 객체 생성
//데이터베이스 연결]
//EmployeeDTO 객체 생성-> setter 호출
//UPDATE 쿼리 메소드 호출 -> dto 객체 전달
//수정 작업이 모두 끝나면 수정 폼 페이지로 이동
%>
----------------------------------------------
//Employee_DeleteForm.jsp -> 직원관리. 삭제 폼 화면 구성.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.test.*" %>
<%
//로그인 여부 확인
//관리자 확인
if (session.getAttribute("loginCheck") == null || session.getAttribute("admin") == null) {
response.sendRedirect("Logout.jsp");
}
String deleteOK = request.getParameter("deleteOK");
if (deleteOK == null) {
deleteOK = "false";
}
String url = "deleteCancel()";
String value = request.getParameter("value");
if (value == null) {
value = "";
}
StringBuilder str = new StringBuilder();
EmployeeDAO dao = new EmployeeDAO();
try {
dao.connect();
String wheres = String.format("WHERE emp_id='%s'", value);
String orders = "";
for (EmployeeDTO dto : dao.searchLists(wheres,orders)) {
url = "deleteOk()";
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 deleteOk() {
//확인 버튼 선택한 경우만 삭제 진행
if (confirm("현재 자료를 삭제하시겠습니까?")) {
//삭제 페이지로 이동. emp_id 전달.
var emp_id = document.getElementById("value");
window.location.href = "Employee_Delete.jsp?emp_id="+emp_id.value;
}
}
function deleteCancel() {
alert("삭제 대상을 검색해야 합니다.");
}
function msg() {
if (<%=deleteOK%>) {
alert("삭제가 완료되었습니다.");
}
}
</script>
</head>
<body onload="msg()">
<div>
<div>
<h2>직원관리_직원삭제</h2>
<c:import url="MainMenu.jsp"></c:import>
</div>
<div>
<form method="get" id="myForm">
사번
<input type="text" style="width:200px;"
name="value" id="value" value="<%=value%>">
[<a href="javascript:search()">검색</a>]
[<a href="javascript:<%=url%>">삭제</a>]
<span id="searchMsg" style="color:red;display:none;">사번을 채워야 합니다.</span>
</form>
<table style="width:900px;" class="style00">
<tbody>
<tr>
<th>사번</th>
<th>이름</th>
<th>주민번호</th>
<th>입사일</th>
<th>지역</th>
<th>전화번호</th>
<th>부서</th>
<th>직위</th>
<th>기본급</th>
<th>수당</th>
<th>급여</th>
</tr>
<%=str%>
</tbody>
</table>
</div>
</div>
</body>
</html>
----------------------------------------------
//Employee_Delete.jsp -> 직원관리. 삭제 액션 처리.
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.test.*" %>
<%
//emp_id 수신
//EmployeeDAO 객체 생성
//데이터 연결
//DELETE 쿼리 메소드 호출 -> remove()
String emp_id = request.getParameter("emp_id");
EmployeeDAO dao = new EmployeeDAO();
try {
dao.connect();
dao.remove(Integer.parseInt(emp_id));
}catch(Exception e){
System.out.println(e.toString());
}finally{
dao.close();
}
//삭제 작업이 모두 완료되면 삭제 폼 페이지로 이동
String url = String.format("Employee_DeleteForm.jsp?deleteOK=true");
response.sendRedirect(url);
%>
----------------------------------------------
직원관리 (JSP버전) 완성됨.
-> WAR 파일은 프로젝트 복구용으로 사용하던가,
알집 프로그램으로 압축 풀어서 소스 코드 확인용으로 사용하면 됩니다.
'Java > JSP & Servlet' 카테고리의 다른 글
[20121204] 15일차 (Servlet JDBC 연동) (0) | 2012.12.04 |
---|---|
[20121203] 14일차 (Servlet) (0) | 2012.12.04 |
[20121121] 7일차 (직원관리) (0) | 2012.12.04 |
[20121120] 6일차 (직원관리) (0) | 2012.12.04 |
[20121119] 5일차 (직원관리) (0) | 2012.12.04 |
WRITTEN BY