//context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="">
    <Resource name="jdbc/Oracle"
          auth="Container"
       type="javax.sql.DataSource"  driverClassName="oracle.jdbc.OracleDriver"
       url="jdbc:oracle:thin:@localhost:1521:XE"
       username="carjava"
    password="carjava"
          maxActive="20"
          maxIdle="10"
       maxWait="-1"/>
</Context>
//web.xml
  <filter>                     //<-- Struts2사용위해 필터 매핑 추가
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

//util.DaoAware.java                 //dao에 의존성주입
public interface DaoAware {
    public void setDao(Object dao);
}
//util.SqlMapClientUtil               
public class SqlMapClientUtil {
    private static SqlMapClient sqlMap;
    public static synchronized  SqlMapClient getSqlMap() throws IOException{
        if(sqlMap ==null){
            Reader reader = Resources.getResourceAsReader("SqlMapConfig.xml");
            sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
        }
        return sqlMap;
    }
}
//SqlMapConfig.xml
<?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE sqlMapConfig PUBLIC '-//ibatis.apache.org/DTD sql Map Config 2.0//EN' 'http://ibatis.apache.org/dtd/sql-map-config-2.dtd'>
<sqlMapConfig>
    <transactionManager type="jdbc" commitRequired="false">
        <dataSource type="JNDI">
            <property name="DBJndiContext" value="java:comp/env/jdbc/Oracle"/>
        </dataSource>
    </transactionManager>
    <sqlMap resource="/sqlmap/member.xml"/>
</sqlMapConfig>

//struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC '-//Apache Software Foundation//DTD Struts Configuration 2.0//EN' 'http://struts.apache.org/dtds/struts-2.0.dtd'>
<struts>
    <include file="/struts2/myInfo.xml"/>
</struts>
//struts2.myInfo.xml                 //내정보보기 Controller
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC '-//Apache Software Foundation//DTD Struts Configuration 2.0//EN' 'http://struts.apache.org/dtds/struts-2.0.dtd'>
<struts>
    <package name="myInfo" extends="struts-default" namespace="/myPage/myInfo">
        <interceptors>
            <interceptor-stack name="MySetParams">
                <interceptor-ref name="prepare"/>
                <interceptor-ref name="modelDriven"/>
                <interceptor-ref name="params"/>
            </interceptor-stack>
            <interceptor name="MemberDaoInject" class="interceptors.MemberDaoInterceptor"/>
            <interceptor name="ZipcodeDaoInject" class="interceptors.ZipcodeDaoInterceptor"/>
        </interceptors>
        <global-results>
            <result name="error">/error.jsp</result>
        </global-results>
        <action name="login" class="action.myPage.myInfo.LoginAction" method="login">
            <interceptor-ref name="MySetParams"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result>/index.jsp</result>
        </action>
        <action name="register" class="action.myPage.myInfo.RegisterAction">
            <interceptor-ref name="MySetParams"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result>/index.jsp</result>
        </action>
        <action name="IdOverlap" class="action.myPage.myInfo.IdOverlapAction">
            <interceptor-ref name="params"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result name="success">/myPage/myInfo/idOverlap.jsp</result>
        </action>
        <action name="findAddress" class="action.myPage.myInfo.FindAddressAction">
            <interceptor-ref name="params"/>
            <interceptor-ref name="ZipcodeDaoInject"/>
            <result>/myPage/myInfo/findAddress.jsp</result>
        </action>
        <action name="logout" class="action.myPage.myInfo.LogoutAction">
            <result>/index.jsp</result>
        </action>
        <action name="myInfo" class="action.myPage.myInfo.ViewInfoAction">
            <interceptor-ref name="params"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result>/myPage/myInfo/myInfo.jsp</result>
        </action>
        <action name="updateMyInfo" class="action.myPage.myInfo.UpdateMyInfoAction">
            <interceptor-ref name="MySetParams"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result type="chain">myInfo</result>
        </action>
        <action name="breakMember" class="action.myPage.myInfo.BreakMemberAction">
            <interceptor-ref name="params"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result>/index.jsp</result>
        </action>
        <action name="findId" class="action.myPage.myInfo.FindAccountAction" method="findId">
            <interceptor-ref name="MySetParams"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result>/myPage/myInfo/findResult.jsp</result>
        </action>
        <action name="findPassword" class="action.myPage.myInfo.FindAccountAction" method="findPassword">
            <interceptor-ref name="MySetParams"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result>/myPage/myInfo/findResult.jsp</result>
        </action>
        <action name="updatePassword" class="action.myPage.myInfo.FindAccountAction" method="updatePassword">
            <interceptor-ref name="MySetParams"/>
            <interceptor-ref name="MemberDaoInject"/>
            <result>/index.jsp</result>
        </action>
    </package>
</struts>

//interceptors.MemberDaoInterceptor.java
public class MemberDaoInterceptor implements Interceptor {

    private MemberDAO dao;

    public void destroy() {
        dao = null;
    }

    public void init() {
        dao = new MemberDAO();
    }

    public String intercept(ActionInvocation invocation) throws Exception {
        Object obj = invocation.getAction();
        if (obj instanceof DaoAware) {
            DaoAware action = (DaoAware) obj;
            action.setDao(dao);
        }

        return invocation.invoke();
    }
}

//sqlmap.member.xml
<?xml version="1.0" encoding="x-windows-949"?>
<!DOCTYPE sqlMap PUBLIC '-//ibatis.apache.org/DTD Sql Map 2.0//EN' 'http://ibatis.apache.org/dtd/sql-map-2.dtd'>
<sqlMap>
    <typeAlias type="vo.MemberVO" alias="member"/>
    <typeAlias type="vo.ZipcodeVO" alias="zipcode"/>
    <select id="selectLogin_Member" parameterClass="member" resultClass="member">
        SELECT * FROM member WHERE id=#id# and password=#password#
    </select>
    <select id="selectInfo_Member" parameterClass="String" resultClass="member">
        SELECT * FROM member WHERE id=#id#
    </select>
    <select id="selectIdOverlap" parameterClass="String" resultClass="member">
        SELECT * FROM member WHERE id=#id#
    </select>
    <select id="selectZipcode" parameterClass="String" resultClass="zipcode">
        SELECT * FROM zipcode WHERE dong LIKE '%$dong$%'
    </select>
    <insert id="insertRegister" parameterClass="member">
        INSERT INTO member VALUES(#id#,#password#,#name#,#personal_code1#,#personal_code2#,#address1#,
        #address2#,#cellphone1#,#cellphone2#,#cellphone3#,#email1#,#email2#,'3','0',sysdate)
    </insert>
    <update id="updateMyInfo" parameterClass="member">
        UPDATE member SET password=#password#, name=#name#, address1=#address1#,
        address2 =#address2#, cellphone1=#cellphone1#,cellphone2=#cellphone2#,
        cellphone3=#cellphone3#, email1=#email1#, email2=#email2# WHERE id=#id#
    </update>
    <delete id="deleteMember" parameterClass="String">
        DELETE member WHERE id = #id#
    </delete>
    <select id="selectFindId_Member" parameterClass="member" resultClass="member">
        SELECT id,name,personal_code1 FROM member WHERE name=#name# and personal_code1 = #personal_code1# and personal_code2 = #personal_code2#
    </select>
    <select id="selectFindPassword_Member" parameterClass="member" resultClass="member">
        SELECT id,name,personal_code1,password FROM member WHERE id=#id# and name = #name# and personal_code1 = #personal_code1# and personal_code2 = #personal_code2#
    </select>
    <update id="updatePassword" parameterClass="member">
        UPDATE member SET password=#password# WHERE id = #id#
    </update>
    <select id="selectTotalcount_Member" resultClass="int">
        SELECT count(*) FROM member
    </select>
    <select id="selectList_Member" resultClass="member" parameterClass="vo.PagingVO">
        <![CDATA[
       SELECT *
       FROM (SELECT rownum r, a.*
             FROM (SELECT *
                   FROM member ORDER BY id ASC) a)
       WHERE r >= #start# AND r <= #end#
       ]]>
    </select>
    <update id="updateMemberInfo" parameterClass="member">
        UPDATE member SET password=#password#, name=#name#,
        personal_code1=#personal_code1#, personal_code2=#personal_code2#,
        address1=#address1#, address2 =#address2#, cellphone1=#cellphone1#,
        cellphone2=#cellphone2#, cellphone3=#cellphone3#, grade=#grade#,
        email1=#email1#, email2=#email2# WHERE id=#id#
    </update>
    <update id="updatePage" parameterClass="vo.ForeignAuctionVO">
        <![CDATA[ UPDATE member SET paper = #seqno# WHERE id=#tenderer# ]]>
    </update>
</sqlMap>



신고

'programing > JAVA' 카테고리의 다른 글

File Up & Down  (0) 2009.06.02
Paging  (0) 2009.06.02
FileUtil  (0) 2009.06.02
JSP ibatis+Struts2  (0) 2009.06.02
ConnectionPool  (0) 2009.06.02
Servlet & JSP 1'  (0) 2009.04.15
Posted by 대절님

댓글을 달아 주세요



티스토리 툴바