eclipse構築SSHフレーム詳細


SSHフレームは最もよく使われているフレームの一つです.SSHフレームを構築する時、いつもこのような問題に遭遇する人がいます.SSHフレーム構築の全過程を紹介します.第一歩:準備作業.  eclipse,Struts 2,Spring,Hibernateをダウンロードします.  1.eclipse:eclipseをダウンロードする時、JavaEE版のeclipseをダウンロードすることを提案します.                 もちろん、あなたもeclipse-SDKをダウンロードできます.(eclipse-SDKをダウンロードするにはWeb、Tomcatなどpluginsをダウンロードする必要があります)  2.Struts 2:http://struts.apache.org/download          1)Strutsのjarバッグを導入する.struts-*-all.zipをダウンロードして解凍した後、struts\libディレクトリの下でstrutsのすべての関連jarパッケージです.          その中に5つが必要です.
               Commons-loging-1.0.4.jar,Freemarker-23.13.jar,                Ognl-2.6.11.jar,Struts 2-core-2.16.jar,Xwork-2.12.jar          残りのjarカバンはstrutsに必要なものではありません.あと3つのカバンも導入に注意してください.Tomcatを導入しないと異常が発生する可能性があります.                commons-i-to-1.3.2.jar,commons-fileuplad-1.jar,javassist-3.7.ga.jar          注意:javassist-3.7.ga.jarパッケージはstruts 2-blank-2.2.warプロジェクト例におけるweb-inf/libの下にあります. 
  3.Spring:http://www.springsource.com/download/community         eclipseでダウンロードもできます.具体的な手順はこうです.        1)eclipse-help-Soff ware Updatesを開く.
         2)開いているダイアログで上記の第二項を選択します.
         3)Add Siteボタンをクリックし、URLダイアログが表示されます. 
        4)ダイアログで入力:http://springide.org/updatesite/ OKをクリックします. 
        5)sping IDEを選択してインストール(Install)をクリックします.
  4.Hibernate:http://sourceforge.net/projects/hibernate/files/hibernate3/  5.Jdkのsrc.zipパッケージ導入.(もちろん導入しなくてもいいです.)第二ステップ:  1.Webプロジェクトを作成して、自分で好きな名前を作ります.  2.WEB-INFのweb.xmlファイルを修正し、struts 2の配置を追加します.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>SSHTest</display-name>
    <!-- struts Framework -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
          org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- welcome file -->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
</web-app>
  3.WEB-INF/clasesディレクトリに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>
    <package namespace="/" name="struts2" extends="struts-default">
        <action name="login" method="execute" class="loginAction">
            <result name="success">/WEB-INF/jsp/login.jsp</result>
            <result name="input">/WEB-INF/index.jsp</result>
        </action>
    </package>
</struts>  
   4.Springの配置    1)スプリングバッグを導入します.spring-frame ebook-*.zipを解凍した後、spring-frame ebook-**フォルダのdistディレクトリの下のjarパッケージをプロジェクトに導入します. 
    2)web.xmlファイルを設定します. 
    <!-- Spring Framework -->
    <listener>
        <listener-class>
          org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/applicationContext*.xml
        </param-value>
    </context-param>
     3)appication Contect.xmlファイルを追加します. 
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
    <!-- Action -->
    <bean id="loginAction" scope="prototype" class="action.LoginAction"></bean>
</beans>
     4)SpringとStrutsを整合する.Strutsのlibディレクトリにstruts 2-spring-plugn-*.jarを見つけて、プロジェクトに導入します.  5.Hibernateの配置        1)hibernate-distribution-*.zipを解凍します.hibernate-distribution-*GA\lib\requiredディレクトリのjarパッケージを導入します.                ヒベルナ3.jar                         コアクラス                ANtlr-2.7.6.jar                          コードスキャナー、HQL文を翻訳します.                comons-collection s-31.jar    Apache Commonsパッケージの一つに、いくつかのApache開発の集合類が含まれています.                                                                機能はjava.util.*より強いです.                dom 4 j-1.6.1.jar                        JavaのXML APIはjdomに似ています.XMLファイルを読むためのものです.                javassist-3.4.GA.jar                 Javassistバイトコードインタプリタ                jta-1.11.jar                                標準的なJTA API                slaf 4 j-api-1.5.jar                sf 4 j-nop-1.5.jar        2)Hibernateプロファイルを作成します.WEB-INF/carsesディレクトリの下にリンクデータベースのプロファイルhiberg.xmlを作成します.             (私は怠け者で、会社のパソコンにはAccessしかないし、他のDBMSもダウンロードしないので、例はAccessに接続している人は我慢して見てください.             *注意:Access UJDBC 30.0 jarを導入する必要があります.    hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC   
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"   
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="connection.driver_class">
            com.hxtt.sql.access.AccessDriver   
        </property>
        <property name="connection.url">
            jdbc:access:///D:/workspace/SSHTest/TestDatabase.accdb
        </property>
        <!--          -->
        <property name="eclipse.connection.profile">access</property>
        <property name="connection.username"></property>
        <property name="connection.password"></property>
        <property name="dialect">com.hxtt.support.hibernate.HxttAccessDialect</property>
        <!-- show_sql   SQL   -->
        <property name="show_sql">true</property>
        <!-- SQL dialect    -->
        <property name="hibernate.dialect">
            com.hxtt.support.hibernate.HxttAccessDialect   
        </property>
        <!--           -->
        <mapping resource="Login.hbm.xml" />
          
        <!-- Annotation    
        <mapping class="entity.Login"/>
         -->
    </session-factory>
</hibernate-configuration>
              注意:Hbernateを単独で使用するには、Session工場類Hibern Session Factory.javaを作成する必要があります.                      (Springで統合すれば不要です.Springはappication Contact.xmlで作成されます.)                       Hibernaのデータベースに対する操作はSessionによって実現され、ここでのsessionはページ間のパラメータを転送するセッションとは異なり、                       JDBCのConnectionに似ています.SessionはHibernateが動作する中心です.                       対象のライフサイクル、事務の管理、データベースのアクセスはセッションと密接に関係しています.                       SessionはHiberga Session Factoryによって作成されました.スレッドは安全です.                       複数の実行スレッドにデータ共有の問題がないように、ヒベルナSession Factoryに同時にアクセスさせることができます.                       複数のスレッドに一つのセッションを共有させることはできません.       3)Loging.hbm.xmlファイル
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="  ">
    <class name="  " table="  ">
        <id name="   java      " column="      " type="   ">
            <generator class="      "/>
        </id>
    </class>
</hibernate-mapping>
 
  6.Spring Hibernateを統合します.Springは、hibernateのSessionの作成、提出、クローズのライフサイクル全体を管理します.         1)  session Factoryを配置して、springにSessionを作成させます.appication Contect.xmlには以下のコードが追加されます.
<!-- sessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
       <property name="configLocation">
           <value>classpath:/hibernate.cfg.xml</value>
       </property>
    </bean>