2013년 8월 11일 일요일

더더더더더... 쉬운 스트럿츠 게시판입니다. 마지막으로 검색입니다.-2

검색이 추가된 소스입니다.
////////// board.action.BoardListAction /////////////////////////////

//============================================================================
/**
  * 시스템명  : board > action > 게시물 리스트 보기
  * 작 성 일  : 2005-07-06
  * 작 성 자  : 김길재
  * 수 정 자  :
  * 파 일 명  : board.action.BoardListAction
  * 버    전  : 1.0
  * 개    요  : 게시물 리스트 보기
  * 이    력  : 2005-07-06 : 초기 작성
  *
  */
//============================================================================


오라클자바커뮤니티에서 설립한 오엔제이프로그래밍 실무교육센터
(오라클SQL, 튜닝, 힌트,자바프레임워크, 안드로이드, 아이폰, 닷넷 실무전문 강의)  

/*
 * Created on 2005. 7. 3
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package board.action;

import java.util.List;
import java.util.ArrayList;
import org.apache.struts.action.*;
import javax.servlet.http.*;

import board.model.BoardDAO;


/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class BoardListAction extends Action
{
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                          HttpServletRequest request , HttpServletResponse res)
    {
            String current_page = "";            //현재 페이지
            String search_type = "";              //검색 타입
                    String search_keyword = "";          //검색 값
                   
                    if( request.getParameter( "current_page" ) != null )
                    {
                            current_page = request.getParameter( "current_page" );
                    }
                    else
                    {
                            current_page = request.getAttribute( "current_page" ).toString();
                    }
                   
                    HttpSession session = request.getSession();
                    BoardDAO boardDAO = new BoardDAO();
            List boardList = new ArrayList();
           
            //검색모드 여부에 따라 다른 함수를 호출하여 리스트에 저장
                    if( session.getAttribute( "search") == null )
                    {
                            boardList = boardDAO.getBoardList( current_page );
                    }
                    else if( session.getAttribute( "search") != null )
                    {
                            search_type = session.getAttribute( "search_type" ).toString();
                            search_keyword = session.getAttribute( "search_keyword" ).toString();
                            boardList = boardDAO.getBoardList( current_page , search_type , search_keyword );
                    }
           
           
            request.setAttribute( "boardList" , boardList );
           
            return (mapping.findForward("board_list_success"));
    }
   
   
}
검색과 관련된 변수들을 세션에서 제거하는 액션입니다.
////////////////////board.action.BackToBoardListAction ////////////
/*
 * Created on 2005. 7. 9
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package board.action;

import org.apache.struts.action.*;
import javax.servlet.http.*;


/**
 * @author Administrator
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class BackToBoardListAction extends Action
{
        public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request , HttpServletResponse res)
        {
                //세션에 있는 검색 관련 값들을 제거하고 BoardListAction을 호출한다.       
                HttpSession session = request.getSession();
               
                session.removeAttribute( "search_type" );
                session.removeAttribute( "search_keyword" );
                session.removeAttribute( "search" );
               
                request.setAttribute( "current_page" , "1" );
                               
                return (mapping.findForward( "back_to_board_list_success" ));
        }

}

///////////// struts-confix.xml //////////////////////////////////////////////
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
     
    <!-- ========== Form Bean Definitions ================================== -->
    <form-beans>
        <!-- ========== login ============== -->
                <!-- ========== search ============== -->
        <form-bean name="BoardSearchForm" type="board.model.BoardSearchForm"/>   

    </form-beans>
   
 
    <!-- ========== Global Forward Definitions =============================== -->
    <global-forwards>
        <forward name="board_search_success"        path="/BoardList.do" />
        <forward name="back_to_board_list_success"  path="/BoardList.do" />
       
    </global-forwards>
   
    <!-- ========== Action Mapping Definitions =============================== -->
    <action-mappings>
               
        <!-- ========== search ============== -->
        <action         
                path="/BoardSearch"
                type="board.action.BoardSearchAction"
                    name="BoardSearchForm"     
                    input="/board/board_list.jsp"                   
                    validate="false">
        </action>
       
        <!-- ========== back to list ============== -->
        <action         
                path="/BackToBoardList"
                type="board.action.BackToBoardListAction">
        </action>
       
    </action-mappings> 
   
    <!-- LANGUAGE SETTING  -->
    <controller
            contentType="text/html;charset=euc-kr"
            debug="3"           
            locale="true"
            nocache="true"   
            processorClass="kkjae.MyFilter"/>
   
</struts-config>

댓글 없음:

댓글 쓰기