/* 
    IntraPMS Project
    부서 관리를 한 후 모든 부서를 보여주는 서블릿

    
*/
import java.io.* ;
import javax.servlet.* ;
import javax.servlet.http.* ;

import java.util.*;

import java.sql.DriverManager ;
import java.sql.Connection ;
import java.sql.Statement ;
import java.sql.ResultSet ;
import java.sql.SQLException ;

import com.etri.groupware.*;
import com.etri.groupware.organization.*;

public class ShowAllDepartmentServlet extends HttpServlet
{
	GroupwareControllerInterface gc = null ;
	OrganizationManagementControllerInterface  omc = null ;
	Properties myPro = null ;

	public void init ( ServletConfig config ) throws ServletException {
		super.init ( config ) ;
		System.out.println ( "ShowAllDepartmentServlet init () Call..........." ) ;
		
		// 그룹웨어 컨트롤러를 생성한다.
		// 먼저 프라퍼티를 생성한다.
		myPro = new Properties ( ) ;
		// DB매니저 구현 클래스 이름 설정
		myPro.put ( "OrganizationDBManagerClassName" , "PandaSoftOrganizationDBManager" ) ;
		myPro.put ( "BBSDBManagerClassName" , "PandaSoftBBSDBManager" ) ;
		myPro.put ( "EDADBManagerClassName" , "PandaSoftEDADBManager" ) ;
		myPro.put ( "MailDBManagerClassName" , "PandaSoftMailDBManager" ) ;
		////////////////////////////////////////
		System.out.println ( "모든 부서를 보여주는 서블릿의 프라퍼티 설정을 무사히 마쳤습니다." ) ;
		
		try {
			gc = GroupwareController.init ( myPro ) ;
			/////////////////////////////////////////////////
			System.out.println ( "모든 부서를 보여주는 서블릿에서 사용하는 그룹웨어 컨트롤러 생성을 무사히 마쳤습니다." ) ;
			
			// 조직도 관리 컨트롤러를 가져온다.
			omc = gc.createOrganizationManagementController ( ) ;
			///////////////////////////////////////////////////////////
			System.out.println ( "모든 부서를 보여주는 서블릿에서 사용하는 조직도 관리 컨트롤러 생성도 무사히 마쳤습니다." ) ;
		} catch ( Exception e ) { }

	}
	
	public void destroy ( ) {
		super.destroy();
		DBConnectionManager.instance.release() ;		
		System.out.println ( "ShowAllDepartmentServlet destroy () Call..........." ) ;
	}

	/*----------------------------------------------------------------- */
	/**
	 [메소드이름]: doGet<br>
	 [기능]: 부서 등록 또는 변경 또는 삭제를 한 후 모든 부서를 보여준다.<br>
	 [파라미터]: HttpServletRequest request, HttpServletResponse response<br>
	 [호출자] : 사용자<br>
	 */
	/*--------------------------------------------------------------- */		
	public void doGet (
		HttpServletRequest request ,
		HttpServletResponse response ) throws ServletException , IOException
	{
		PrintWriter out ;
		String head = " 팬더 소프트 " ;
		// Set content type and other response header fields first
		response.setContentType ( "text/html;charset=euc-kr" ) ;
		// then write the data of the response
		out = new PrintWriter ( new OutputStreamWriter ( response.getOutputStream ( ) , "EUC-KR" ) ) ;
		
		/////////////////////////////////////////////
		// 세션 확인 부분 - 인증되지 않은 사용자의 경우 Login.html 로 되돌려 보낸다.
		String authenKind = null ;
		String authenId = null ;
		String authenName = null ;
		String authenLoginStatus = null;
		
		HttpSession session = request.getSession ();
		authenLoginStatus =  (String)session.getValue("Authentication");
		
		if( (authenLoginStatus == null) || ( !(authenLoginStatus.equals("true")) ) ){
			session.invalidate();
			response.sendRedirect("../Login.html");
		} else {
			authenKind = (String)session.getValue("Kind");
			authenId = (String)session.getValue("Id");
			authenName = (String)session.getValue("Name");   
		}
		/////////////////////////////////////////////

		// 데이타베이스에서 가져온 모든 부서의 내용으로 Department의 배열형태이다.
		Department[] allDepartment = null ;
		boolean isUpdateTree = false ;
		boolean isSearch = false ;
		String page = request.getParameter("page");		
		page = new String ( page.getBytes("ISO-8859-1") , "EUC-KR" ) ;

		if ( (request.getParameter("up")!= null ) ) isUpdateTree = true ;

		if ( (request.getParameter("name")!=null) || (request.getParameter ("search")!=null) ) {
			// 등록,삭제,변경,검색 버튼이 눌러졌을 경우에 새로운 팀을 등록,삭제,변경하고 이 부서의 팀 리스트를 보여준다.
			
			String name = null ;
			String weightWork = null ;
			String phoneNumber = null ;
			String faxNumber = null ;
			String webURL = null ;
			String departmentExplain = null ;
			Department newDep = null ;
			// 폼 태그의 변수 값을 얻는다.
			// 검색일 경우 얻으면 에러가 난다.
			if ( request.getParameter("two_search")!=null ) {
				// 검색일 경우이다.
			} else {
				
			name = request.getParameter ( "name" ) ;		
			name = new String ( name.getBytes("ISO-8859-1") , "EUC-KR" ) ;
			weightWork = request.getParameter ( "weightWork" ) ;
			weightWork = new String ( weightWork.getBytes("ISO-8859-1") , "EUC-KR" ) ;
			phoneNumber = request.getParameter ( "phoneNumber" ) ;
			phoneNumber = new String ( phoneNumber.getBytes("ISO-8859-1") , "EUC-KR" ) ;
			faxNumber = request.getParameter ( "faxNumber" ) ;
			faxNumber = new String ( faxNumber.getBytes("ISO-8859-1") , "EUC-KR" ) ;
			webURL = request.getParameter ("webURL") ;
			webURL = new String ( webURL.getBytes("ISO-8859-1") , "EUC-KR" ) ;
			departmentExplain = request.getParameter ( "departmentExplain" ) ;
			departmentExplain = new String ( departmentExplain.getBytes("ISO-8859-1") , "EUC-KR" ) ;
			
			newDep = new Department ( ) ;
			newDep.setName ( name ) ;
			newDep.setWeightWork ( weightWork) ;
			newDep.setPhoneNumber ( phoneNumber ) ;
			newDep.setFaxNumber ( faxNumber ) ;
			newDep.setWebURL ( webURL ) ;
			newDep.setDepartmentExplain ( departmentExplain ) ;
			
			}
			
			if ( request.getParameter ( "delete" ) != null ) {
				// 삭제하기 버튼을 눌렀을 경우....
				omc.deleteDepartment ( newDep ) ;
				// 데이타 베이스에서 삭제했습니다.		
				isUpdateTree = true ;
				// 데이타 베이스에서 모든 부서의 내용을 가져온다.
				allDepartment = omc.getAllDepartment ( ) ;
			} else if ( request.getParameter ( "update" ) != null ) {
				// 변경하기 버튼을 눌렀을 경우....
				omc.updateDepartment ( newDep ) ;
				// 데이타 베이스에 업 데이트했습니다.
				// 데이타 베이스에서 모든 부서의 내용을 가져온다.
				allDepartment = omc.getAllDepartment ( ) ;
			} else if ( request.getParameter ( "search" ) != null ) {
				// 검색하기 버튼을 눌렀을 경우....
				isSearch = true ;
			
				if ( request.getParameter("first_search") != null ) {
					DepartmentSearchProperty dsp = new DepartmentSearchProperty ( ) ;
					dsp.setName ( name ) ;
					dsp.setWeightWork ( weightWork ) ;
					if ( request.getParameter ( "orAnd" ).equals ( "or" ) ) {
						dsp.setOrOrAnd ( true ) ;
					} else {
						dsp.setOrOrAnd ( false ) ;
					}
					dsp.setDepartmentExplain ( departmentExplain ) ;
					// 데이타 베이스에서 검색되어진 모든 부서의 내용을 가져온다.
					allDepartment = omc.searchDepartment ( dsp ) ;
					// 검색 결과가 한 페이지 이상일 경우도 존재하므로 결과를 저장한다.					
					DepartmentSearchResult.setSearchDep ( allDepartment ) ;
				} else {
					// 검색을 다시 하는 것이 아니라 검색된 결과를 가져다 쓰는 경우이다.
					allDepartment = DepartmentSearchResult.getSearchDep( ) ;
				}
			} else {
				// 등록하기 버튼을 눌렀을 경우...
				OrganizationResultStatus ors = omc.addDepartment ( newDep ) ;
				if ( ors.getResultStatus() == 1 ) {
					// 입력하는것에 실패했을 경우
					out.println ( "<html><head><title>에러</title></head>" ) ;
					out.println ( "<body><p align=\"center\">에러가 발생했습니다.</p>" ) ;
					out.println ( "<p align=\"center\">이미 존재하는 부서 이름입니다.</p>" ) ;
					out.println ( "<p align=\"center\">" + ors.getReason() + "</p>" ) ;
					out.println ( "<p align=\"center\"><input type=\"button\" name=\"add\" value=\"되돌아 가기\" onClick=\"history.back();\"></p>" ) ;
					out.println ( "</body></html>" ) ;
					out.close ( ) ;
				}
				isUpdateTree = true ;
				// 데이타 베이스에서 모든 부서의 내용을 가져온다.
				allDepartment = omc.getAllDepartment ( ) ;
			}				
		} else {
			allDepartment = omc.getAllDepartment ( ) ;
		}
		
		if ( allDepartment[0].getName().equals( "error" ) ) {
			out.println ( "<html><head><title>에러</title></head>" ) ;
			out.println ( "<body><p align=\"center\">에러가 발생했습니다.</p>" ) ;
			out.println ( "<p align=\"center\">에러의 내용은 다음과 같습니다.</p>" ) ;
			out.println ( "<p align=\"center\">" + allDepartment[0].getWeightWork() + "</p>" ) ;
			out.println ( "</body></html>" ) ;
			out.close ( ) ;
		} else {
	
			out.println ( "<html><head><title>팬더 소프트</title>" ) ;
			out.println ( "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-kr\">" ) ;
			out.println ( "<style type=\"text/css\">" ) ;
			out.println ( "BODY {font-size:9pt; color:\"#000000\"; line-height:14px;}" ) ;
			out.println ( "A:Link {font-size:9pt; color:\"#000033\"; line-height:14px; text-decoration:none}" ) ;
			out.println ( "A:Visited {font-size:9pt; color:\"#330033\"; line-height:14px; text-decoration:none}" ) ;
			out.println ( "A:Hover {font-size:9pt; color:\"#0000ff\"; line-height:14px; text-decoration:underline}" ) ;
			out.println ( "td {font-size:9pt;}" ) ;
			out.println ( "td.red {font-size:9pt; color:\"#ff0000\"}" ) ;
			out.println ( "td.black {font-size:9pt; color:\"#000000\"}" ) ;
			out.println ( "td.navy {font-size:9pt; color:\"#000066\"}" ) ;
			out.println ( "td.space {font-size:1pt;}" ) ;
			out.println ( "</style>  </HEAD>" ) ;
			
			if ( isUpdateTree ) {
				out.println ( "<body onLoad=\"updateOrgTree()\">" ) ;
			} else {
				out.println ( "<body>" ) ;
			}
			out.println ( "<p align=right><img src=\"/image/우측_관리기능.gif\" alt=\"관리 기능\"></p>" ) ;
			
			out.println ( "<script language=\"JavaScript\">" ) ;
			out.println ( "<!--" ) ;
			out.println ( "	function updateOrgTree()" ) ;
			out.println ( "	{ " ) ;
			out.println ( "		parent.frames[\'contents\'].location=\"/servlet/ShowOrganizationTreeServlet\"; " ) ;
			out.println ( "	} " ) ;
			out.println ( "//-->" ) ;
			out.println ( "</script>" ) ;
			
			out.println ( "<form><table border=0 hspace=1 width=800 cellpadding=3><tr width=800><td width=340>" ) ;	
			if ( isSearch ) {
				out.println ( "<a href=\"/servlet/ShowOrganizationTreeServlet\" target=\"contents\" onClick=\"parent.frames[\'detail\'].location=\'/orgdetail.html\'\">조직관리</a>" ) ;
				out.println ( "</td><td width=460 align=right>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?add=add\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depAdd.src='/image/부서등록-1.jpg'\" onMouseOut=\"document.forms[0].depAdd.src='/image/부서등록.jpg'\"><img name=depAdd src=\"/image/부서등록.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?search=search\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depSea.src='/image/부서검색-1.jpg'\" onMouseOut=\"document.forms[0].depSea.src='/image/부서검색.jpg'\"><img name=depSea src=\"/image/부서검색.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?add=add&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temAdd.src='/image/팀등록-1.jpg'\" onMouseOut=\"document.forms[0].temAdd.src='/image/팀등록.jpg'\"><img name=temAdd src=\"/image/팀등록.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?search=search&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temSea.src='/image/팀검색-1.jpg'\" onMouseOut=\"document.forms[0].temSea.src='/image/팀검색.jpg'\"><img name=temSea src=\"/image/팀검색.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?add=add&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offAdd.src='/image/사원등록-1.jpg'\" onMouseOut=\"document.forms[0].offAdd.src='/image/사원등록.jpg'\"><img name=offAdd src=\"/image/사원등록.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?search=search&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offSea.src='/image/사원검색-1.jpg'\" onMouseOut=\"document.forms[0].offSea.src='/image/사원검색.jpg'\"><img name=offSea src=\"/image/사원검색.jpg\"></a>" ) ;
				out.println ( "</td></tr><tr width=800 valign=middle bgcolor=\"#3399ff\"><td colspan=2 width=800><nobr><FONT color=#ffffff>부서 검색 결과</nobr></td></tr></table>" ) ;
			} else {
				out.println ( "<a href=\"/servlet/ShowOrganizationTreeServlet\" target=\"contents\" onClick=\"parent.frames[\'detail\'].location=\'/orgdetail.html\'\">조직관리</a>" ) ;
				out.println ( "</td><td width=460 align=right>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?add=add\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depAdd.src='/image/부서등록-1.jpg'\" onMouseOut=\"document.forms[0].depAdd.src='/image/부서등록.jpg'\"><img name=depAdd src=\"/image/부서등록.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchDepartmentServlet?search=search\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].depSea.src='/image/부서검색-1.jpg'\" onMouseOut=\"document.forms[0].depSea.src='/image/부서검색.jpg'\"><img name=depSea src=\"/image/부서검색.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?add=add&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temAdd.src='/image/팀등록-1.jpg'\" onMouseOut=\"document.forms[0].temAdd.src='/image/팀등록.jpg'\"><img name=temAdd src=\"/image/팀등록.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchTeamServlet?search=search&upDep=upDep\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].temSea.src='/image/팀검색-1.jpg'\" onMouseOut=\"document.forms[0].temSea.src='/image/팀검색.jpg'\"><img name=temSea src=\"/image/팀검색.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?add=add&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offAdd.src='/image/사원등록-1.jpg'\" onMouseOut=\"document.forms[0].offAdd.src='/image/사원등록.jpg'\"><img name=offAdd src=\"/image/사원등록.jpg\"></a>" ) ;
				out.println ( "<a onClick=\"parent.frames[\'detail\'].location=\'/servlet/AddSearchOfficialServlet?search=search&upDep=null&team=null\'\" style=\"cursor:hand;\" onMouseOver=\"document.forms[0].offSea.src='/image/사원검색-1.jpg'\" onMouseOut=\"document.forms[0].offSea.src='/image/사원검색.jpg'\"><img name=offSea src=\"/image/사원검색.jpg\"></a>" ) ;
				out.println ( "</td></tr><tr width=800 valign=middle bgcolor=\"#3399ff\"><td colspan=2 width=800><nobr><FONT color=#ffffff>팬더 소프트" + "의 모든 부서 보기</nobr></td></tr></table></form>" ) ;
			}
	
			out.println ( "<p><p><!--------바뀌는  테이블------------>" ) ;
			out.println ( "<!--td align=\"center\" valign=\"top\"--> " ) ;
			out.println ( "<p><p><center><table width=\"731\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> " ) ;
			out.println ( "  <tr> " ) ;
			out.println ( "    <td width=\"10\">&nbsp;</td>" ) ;
			out.println ( "    <td width=\"10\">&nbsp;</td>"  ) ;
			out.println ( "    <td width=\"711\">&nbsp;</td>" ) ;
			out.println ( "  </tr>  <tr> " ) ;
			out.println ( "    <td width=\"10\">&nbsp;</td>" ) ;
			out.println ( "    <td width=\"10\">&nbsp;</td>" ) ;
			out.println ( "    <td width=\"711\">&nbsp;</td>" ) ;
			out.println ( "  </tr>  <tr> " ) ;
			out.println ( "    <td width=\"10\">&nbsp;</td>" ) ;
			out.println ( "    <td width=\"10\">&nbsp;</td>" ) ;
			out.println ( "    <td width=\"711\">&nbsp;</td>" ) ;
			out.println ( "  </tr></table>" ) ;
			out.println ( "<table width=\"710\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\">" ) ;
			out.println ( "	<tr>	<td>&nbsp;&nbsp;&nbsp;</td>	<td>" ) ;
			out.println ( "<table border=0 cellpadding=2 cellspacing=0 bgcolor=#3399ff>" ) ;
			out.println ( "<tr><td width=600>" ) ;
			out.println ( "<table width=\"710\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\">" ) ;
			out.println ( "	<tr>	<td width=130 align=center bgcolor=#3399ff>부서 이름</td>" ) ;
			out.println ( "	<td width=290 align=center bgcolor=#3399ff>부서 주요 업무</td>" ) ;
			out.println ( "	<td width=290 align=center bgcolor=#3399ff>부서 설명</td>" ) ;
			out.println ( "	</tr>" ) ;
			
			////////////////////////////////////////////////////
			// 페이지를 위해 부서의 갯수를 알아내자....
			int dbNumber = 0 ;
			for ( dbNumber = 0 ; !(allDepartment[dbNumber].getName().equals("null")) ; dbNumber++ ) { }
			// 지금부터는 [dbNumber] 가 총 부서의 갯수이다.
			////////////////////////////////////////////////////
			// 이제 총 페이지의 갯수를 알아내자..
			int pageNumber = dbNumber/4 ;
			if ( dbNumber%4 != 0 ) pageNumber++ ;
			// 파라미터로 현재 페이지를 얻어낼수 있다.
			// 파라미터로 넘어온 현재 페이지는 curPage이다.
			System.out.println ( page ) ;
			int curPage = Integer.parseInt ( page ) ;
			// 현재 페이지의 수에 맞추어서 튜플을 건너 뛰어야한다.
			int loop = ((curPage-1)*4) ;
			/////////////////////////////////////////////////
			// 라스트 페이지를 구해보자.
			int last = 0 ;
			if ( (pageNumber%3)==1 ) last = pageNumber ;
			else if ( (pageNumber%3)==2 ) last = pageNumber-1 ;
			else if ( (pageNumber%3)==0 ) last = pageNumber-2 ;
			String lastPage = new String ( Integer.toString ( last ) ) ;
			// Pre 페이지를 구해보자.
			int pre = 0 ;
			if ( (curPage%3)==1 ) pre = curPage-3 ;
			else if ( (curPage%3)==2 ) pre = curPage-4 ;
			else if ( (curPage%3)==0 ) pre = curPage-5 ;
			String prePage = new String ( Integer.toString ( pre ) ) ;
			// Next 페이지를 구해보자.
			int next = 0 ;
			if ( (curPage%3)==1 ) next = curPage+3 ;
			else if ( (curPage%3)==2 ) next = curPage+2 ;
			else if ( (curPage%3)==0 ) next = curPage+1 ;
			String nextPage = new String ( Integer.toString ( next ) ) ;
			// curPage에 대한 것들을 String으로 바꾸자.
			// curPage ( int ) 이고 page ( String ) 입니다.
			String mmPage = new String ( Integer.toString ( curPage-2 ) ) ;
			String mPage = new String ( Integer.toString ( curPage-1 ) ) ;
			String pPage = new String ( Integer.toString ( curPage+1 ) ) ;
			String ppPage = new String ( Integer.toString ( curPage+2 ) ) ;
			/////////////////////////////////////////////////////////////////
			boolean stop = false ;						
			
			out.println ( "    <tr>" ) ;
			if ( allDepartment[loop].getName().equals("null") ) {
				stop = true ;
			} else {
				//지금부터는 index대신 loop를 사용한다.
				out.println ( "<TD bgcolor=\'#f7f7f7\'><a href=\"/servlet/ShowAllTeamServlet?page=1&name=" + allDepartment[loop].getName() + "\" target=\"detail\">" + allDepartment[loop].getName() + "</A></TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getWeightWork() + "</TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getDepartmentExplain() + "</TD>" ) ;
			
				loop++ ;
			}
			out.println ( "    </tr>" ) ;
			out.println ( "    <tr>" ) ;
	
			if ( allDepartment[loop].getName().equals("null") ) {
				stop = true ;
			out.println ( "<TD bgcolor=\'#f7f7f7\'>&nbsp;</TD><TD bgcolor=\'#f7f7f7\'>&nbsp;</TD><TD bgcolor=\'#f7f7f7\'>&nbsp;</TD>" ) ;
			} else {
				out.println ( "<TD bgcolor=\'#f7f7f7\'><a href=\"/servlet/ShowAllTeamServlet?page=1&name=" + allDepartment[loop].getName() + "\" target=\"detail\">" + allDepartment[loop].getName() + "</A></TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getWeightWork() + "</TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getDepartmentExplain() + "</TD>" ) ;
				
				loop++ ;
			}
			out.println ( "    </tr>" ) ;
			out.println ( "    <tr>" ) ;
			if ( (allDepartment[loop].getName().equals("null")) || (stop==true) ) {
				stop = true ;
				out.println ( "<TD bgcolor=\'#f7f7f7\'>&nbsp;</TD><TD bgcolor=\'#f7f7f7\'>&nbsp;</TD><TD bgcolor=\'#f7f7f7\'>&nbsp;</TD>" ) ;
			} else {
				out.println ( "<TD bgcolor=\'#f7f7f7\'><a href=\"/servlet/ShowAllTeamServlet?page=1&name=" + allDepartment[loop].getName() + "\" target=\"detail\">" + allDepartment[loop].getName() + "</A></TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getWeightWork() + "</TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getDepartmentExplain() + "</TD>" ) ;
				
				loop++ ;
			}
			out.println ( "    </tr>" ) ;
			out.println ( "    <tr>" ) ;
			if ( (allDepartment[loop].getName().equals("null")) || (stop==true) ) {
				out.println ( "<TD bgcolor=\'#f7f7f7\'>&nbsp;</TD><TD bgcolor=\'#f7f7f7\'>&nbsp;</TD><TD bgcolor=\'#f7f7f7\'>&nbsp;</TD>" ) ;
			} else {
				out.println ( "<TD bgcolor=\'#f7f7f7\'><a href=\"/servlet/ShowAllTeamServlet?page=1&name=" + allDepartment[loop].getName() + "\" target=\"detail\">" + allDepartment[loop].getName() + "</A></TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getWeightWork() + "</TD>" ) ;
				out.println ( "<TD align=center bgcolor=\'#f7f7f7\'>" + allDepartment[loop].getDepartmentExplain() + "</TD>" ) ;
			}
			
			out.println ( "    </tr>" ) ;		
			out.println ( "</table>" ) ;
			out.println ( "			<!----------------------------------글 리스트보여주는 테이블의 끝-------------------------->" ) ;
			out.println ( "</td></tr></table>" ) ;
			out.println ( "<!----------------------------------글 리스트 보여주는 테이블을 약간 오른쪽으로 하기위한 큰 테이블의 끝 ------->" ) ;
			out.println ( "</td></tr></table></center><br>" ) ;
	
			out.println ( "<table align=center><tr align=center>" ) ;			
			System.out.println ( "모든 테이블을 출력했습니다..." ) ;
			
			if ( isSearch ) {
			//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			// 페이지의 숫자를 이용하여 몇번째 tuple부터 가져올지를 알 수 있다.
			// 그래서 4개의 데이타를 모두 써주 었다.
			// 이제 마지막 줄은 여러가지 형태로 나올 수 있다.
			if ( pageNumber == 0 ) {
			// 데이타 베이스에 데이타가 하나도 없는 경우이다.
			//out.println ( "<p align=\"center\">부서가 존재하지 않습니다.</p> " ) ;
			//out.println ( "<p align=\"center\">새로운 부서를 등록해 주십시요.</p> " ) ;
			} else	if ( curPage == 1 ) {
			if ( pageNumber == 1 ) {
				// 총 페이지가 1개인 경우이다. 이때는 [1] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
			} else if ( pageNumber == 2 ) {
				// 총 페이지가 2개인 경우이다. 이때는 [1][2] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2&search=search&two_search=ok\">[2]</font></a></TD>" ) ;
			} else if ( pageNumber == 3 ) {
				// 총 페이지가 3개인 경우이다. 이때는 [1][2][3] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2&search=search&two_search=ok\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3&search=search&two_search=ok\">[3]</font></a></TD>" ) ;
			} else if ( pageNumber > 3 ) {
				// 총 페이지가 4개 이상인 경우이다. 이때는 [1][2][3] [next] [last] 의 형태이다. 
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2&search=search&two_search=ok\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3&search=search&two_search=ok\">[3]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=4&search=search&two_search=ok\">[Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "&search=search&two_search=ok\">[Last]</font></a></TD>" ) ;
			}
			} else if ( curPage == 2 ) {
			if ( pageNumber == 1 ) {
				// 잘못된 파라미터이다.
				out.println ( "<p align=\"center\">잘못된 파라미터 입니다.</p> " ) ;
			} else if ( pageNumber == 2 ) {
				// 총 페이지가 2개인 경우 이다. 이때는 [1][2] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[2]</font></TD>" ) ;
			} else if ( pageNumber == 3 ) {
				// 총 페이지가 3개인 경우이다. 이때는 [1][2][3] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[2]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3&search=search&two_search=ok\">[3]</font></a></TD>" ) ;
			} else if ( pageNumber > 3 ) {
				// 총 페이지가 4개 이상인 경우이다. 이때는 [1][2][3] [next] [last] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[2]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3&search=search&two_search=ok\">[3]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=4&search=search&two_search=ok\">[Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "&search=search&two_search=ok\">[Last]</font></a></TD>" ) ;					
			}						
			} else if ( curPage == 3 ) {
			if ( pageNumber == 1 ) {
				// 잘못된 파라미터이다.
				out.println ( "<p align=\"center\">잘못된 파라미터 입니다.</p> " ) ;
			} else if ( pageNumber == 2 ) {
				// 잘못된 파라미터이다.
				out.println ( "<p align=\"center\">잘못된 파라미터 입니다.</p> " ) ;
			} else if ( pageNumber == 3 ) {
				// 총 페이지가 3개인 경우이다. 이때는 [1][2][3] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2&search=search&two_search=ok\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[3]</font></TD>" ) ;
			} else if ( pageNumber > 3 ) {
				// 총 페이지가 4개 이상인 경우이다. 이때는 [1][2][3] [next] [last] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2&search=search&two_search=ok\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[3]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=4&search=search&two_search=ok\">[Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "&search=search&two_search=ok\">[Last]</font></a></TD>" ) ;					
			}					
			} else if ( (((curPage%3)==1)&&((curPage+2)<pageNumber)) || (((curPage%3)==2)&&((curPage+1)<pageNumber)) || (((curPage%3)==0)&&(curPage<pageNumber)) ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x][x][x][next][last]  의 형태일 경우..
			if ( (curPage%3)==1 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\">[First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "&search=search&two_search=ok\"> [" + pPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + ppPage + "&search=search&two_search=ok\"> [" + ppPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + nextPage + "&search=search&two_search=ok\"> [Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "&search=search&two_search=ok\"> [Last]</font></a></TD>" ) ;					
			} else if ( (curPage%3)==2) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "&search=search&two_search=ok\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "&search=search&two_search=ok\"> [" + pPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + nextPage + "&search=search&two_search=ok\"> [Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "&search=search&two_search=ok\"> [Last]</font></a></TD>" ) ;					
			} else if ( (curPage%3)==0) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mmPage + "&search=search&two_search=ok\"> [" + mmPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "&search=search&two_search=ok\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + nextPage + "&search=search&two_search=ok\"> [Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "&search=search&two_search=ok\"> [Last]</font></a></TD>" ) ;					
			}
			} else if ( (pageNumber%3)==1 ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x] 의 형태일 경우...
			out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
			out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
			out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
			} else if ( (pageNumber%3)==2 ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x][x] 의 형태일 경우...
			if ( (curPage%3)==1 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "&search=search&two_search=ok\"> [" + pPage + "]</font></a></TD>" ) ;
			} else if ( (curPage%3)==2 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "&search=search&two_search=ok\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
			}
			} else if ( (pageNumber%3)==0 ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x][x][x] 의 형태일 경우...
			if ( (curPage%3)==1 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "&search=search&two_search=ok\"> [" + pPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + ppPage + "&search=search&two_search=ok\"> [" + ppPage + "]</font></a></TD>" ) ;
			} else if ( (curPage%3)==2 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "&search=search&two_search=ok\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "&search=search&two_search=ok\"> [" + pPage + "]</font></a></TD>" ) ;
			} else if ( (curPage%3)==0 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1&search=search&two_search=ok\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "&search=search&two_search=ok\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mmPage + "&search=search&two_search=ok\"> [" + mmPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "&search=search&two_search=ok\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
			}
			}
			System.out.println ( "페이지를 3개씩 출력했습니다..." ) ;
			
			out.println ( "</tr></table><br>" ) ;
			} else {
	
	
			// 페이지의 숫자를 이용하여 몇번째 tuple부터 가져올지를 알 수 있다.
			// 그래서 4개의 데이타를 모두 써주 었다.
			// 이제 마지막 줄은 여러가지 형태로 나올 수 있다.
			if ( pageNumber == 0 ) {
			// 데이타 베이스에 데이타가 하나도 없는 경우이다.
			//out.println ( "<p align=\"center\">부서가 존재하지 않습니다.</p> " ) ;
			//out.println ( "<p align=\"center\">새로운 부서를 등록해 주십시요.</p> " ) ;
			} else	if ( curPage == 1 ) {
			if ( pageNumber == 1 ) {
				// 총 페이지가 1개인 경우이다. 이때는 [1] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
			} else if ( pageNumber == 2 ) {
				// 총 페이지가 2개인 경우이다. 이때는 [1][2] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2\">[2]</font></a></TD>" ) ;
			} else if ( pageNumber == 3 ) {
				// 총 페이지가 3개인 경우이다. 이때는 [1][2][3] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3\">[3]</font></a></TD>" ) ;
			} else if ( pageNumber > 3 ) {
				// 총 페이지가 4개 이상인 경우이다. 이때는 [1][2][3] [next] [last] 의 형태이다. 
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[1]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3\">[3]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=4\">[Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "\">[Last]</font></a></TD>" ) ;
			}
			} else if ( curPage == 2 ) {
			if ( pageNumber == 1 ) {
				// 잘못된 파라미터이다.
				out.println ( "<p align=\"center\">잘못된 파라미터 입니다.</p> " ) ;
			} else if ( pageNumber == 2 ) {
				// 총 페이지가 2개인 경우 이다. 이때는 [1][2] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[2]</font></TD>" ) ;
			} else if ( pageNumber == 3 ) {
				// 총 페이지가 3개인 경우이다. 이때는 [1][2][3] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[2]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3\">[3]</font></a></TD>" ) ;
			} else if ( pageNumber > 3 ) {
				// 총 페이지가 4개 이상인 경우이다. 이때는 [1][2][3] [next] [last] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[2]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=3\">[3]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=4\">[Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "\">[Last]</font></a></TD>" ) ;					
			}						
			} else if ( curPage == 3 ) {
			if ( pageNumber == 1 ) {
				// 잘못된 파라미터이다.
				out.println ( "<p align=\"center\">잘못된 파라미터 입니다.</p> " ) ;
			} else if ( pageNumber == 2 ) {
				// 잘못된 파라미터이다.
				out.println ( "<p align=\"center\">잘못된 파라미터 입니다.</p> " ) ;
			} else if ( pageNumber == 3 ) {
				// 총 페이지가 3개인 경우이다. 이때는 [1][2][3] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[3]</font></TD>" ) ;
			} else if ( pageNumber > 3 ) {
				// 총 페이지가 4개 이상인 경우이다. 이때는 [1][2][3] [next] [last] 의 형태이다.
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\">[1]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=2\">[2]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[3]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=4\">[Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "\">[Last]</font></a></TD>" ) ;					
			}					
			} else if ( (((curPage%3)==1)&&((curPage+2)<pageNumber)) || (((curPage%3)==2)&&((curPage+1)<pageNumber)) || (((curPage%3)==0)&&(curPage<pageNumber)) ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x][x][x][next][last]  의 형태일 경우..
			if ( (curPage%3)==1 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\">[First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "\"> [" + pPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + ppPage + "\"> [" + ppPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + nextPage + "\"> [Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "\"> [Last]</font></a></TD>" ) ;					
			} else if ( (curPage%3)==2) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "\"> [" + pPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + nextPage + "\"> [Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "\"> [Last]</font></a></TD>" ) ;					
			} else if ( (curPage%3)==0) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mmPage + "\"> [" + mmPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + nextPage + "\"> [Next]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + lastPage + "\"> [Last]</font></a></TD>" ) ;					
			}
			} else if ( (pageNumber%3)==1 ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x] 의 형태일 경우...
			out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
			out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
			out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
			} else if ( (pageNumber%3)==2 ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x][x] 의 형태일 경우...
			if ( (curPage%3)==1 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "\"> [" + pPage + "]</font></a></TD>" ) ;
			} else if ( (curPage%3)==2 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
			}
			} else if ( (pageNumber%3)==0 ) {
			// 현재 파라미터로 넘어온 페이지가 [first][pre][x][x][x] 의 형태일 경우...
			if ( (curPage%3)==1 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "\"> [" + pPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + ppPage + "\"> [" + ppPage + "]</font></a></TD>" ) ;
			} else if ( (curPage%3)==2 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + pPage + "\"> [" + pPage + "]</font></a></TD>" ) ;
			} else if ( (curPage%3)==0 ) {
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=1\"> [First]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + prePage + "\"> [Pre]</font></a></TD>" ) ;					
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mmPage + "\"> [" + mmPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><a href=\"/servlet/ShowAllDepartmentServlet?page=" + mPage + "\"> [" + mPage + "]</font></a></TD>" ) ;
				out.println ( "<TD align=middle vAlign=center height=21><font color=#ff0000>[" + page + "]</font></TD>" ) ;
			}
			}
			System.out.println ( "페이지를 3개씩 출력했습니다..." ) ;
			
			out.println ( "</tr></table><br>" ) ;
			}
	
			out.println ( "<br>" ) ;
			
			out.println ( "</body></html>" ) ;
								
			out.close ( ) ;
		}
	}
}

			
		