<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    jojo's blog--快樂憂傷都與你同在
    為夢想而來,為自由而生。 性情若水,風(fēng)起水興,風(fēng)息水止,故時而激蕩,時又清平……
    posts - 11,  comments - 30,  trackbacks - 0

    參考了網(wǎng)上好多文章,記不太清了,在此一并感謝!主要有:
    Tapestry整合Spring實踐 http://tech.blogbus.com/logs/2004/06/219144.html

    1、在eclipse中新建tapestry項目,項目名稱tshDemo
    2、菜單myEclipse-->Add Spring Capabilities... ,


    點擊Next> ,注意的一點是,沒有使用myeclipse自帶的jar包,而是選擇User Libraries自己定義的最新的spring開發(fā)包(方法是在Window-->Preferences...-->Java-->Build Path-->User Libraries中定義),為了使WEB-INF/lib目錄下包含相應(yīng)jar包,選擇拷貝到目錄


    點擊Finish,完成對spring支持,有一個不好的是,eclipse會把所有的jar包文件一個個明細(xì)的列在項目名下,倍長非常不方便,修改辦法,在項目屬性-->Java Build Path-->Libraries中,把所有的明細(xì)jar包全部選中刪除,點擊Add Library...-->User Library-->Next> -->勾選相應(yīng)的user library-->Finish 即可

    3、修改web.xml如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app
          PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
          "

    <web-app>
      <display-name>tshDemo</display-name>

      <filter>
        <filter-name>redirect</filter-name>
        <filter-class>org.apache.tapestry.RedirectFilter</filter-class>
        <init-param>
          <param-name>redirect-path</param-name>
          <param-value>/app</param-value>
        </init-param>
      </filter>

      <filter-mapping>
        <filter-name>redirect</filter-name>
        <url-pattern>/</url-pattern>
      </filter-mapping>

      <listener>
        <listener-class>
          org.springframework.web.context.ContextLoaderListener
        </listener-class>
      </listener>

      <servlet>
        <servlet-name>tshDemo</servlet-name>
        <servlet-class>
          org.apache.tapestry.ApplicationServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>tshDemo</servlet-name>
        <url-pattern>/app</url-pattern>
      </servlet-mapping>
    </web-app>

    4、修改applicationContext.xml如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "

    <beans>
      <description>Spring Quick Start</description>
      <bean id="theAction" class="tsh.demo.service.LowerAction">
        <property name="message">
          <value>HeLLo </value>
        </property>
      </bean>

    </beans>

    5、新建3個包,tsh.demo.dao 持久層,tsh.demo.service 中間層,tsh.demo.web 表示層

    6、tapestry支持spring,新建tapestry engine類,如下:
    /*
     * package tsh.demo.web;
     * class tsh.demo.web.EngineWithSpring
     * Created on 2006-1-23, 17:49:43
     */
    package tsh.demo.web;

    import java.util.Map;

    import org.apache.tapestry.engine.BaseEngine;
    import org.apache.tapestry.request.RequestContext;
    import org.springframework.context.ApplicationContext;
    import org.springframework.web.context.support.WebApplicationContextUtils;

    public class EngineWithSpring extends BaseEngine {

     private static final long serialVersionUID = 1L;
     public static final String APPLICATION_CONTEXT_KEY = "appContext";
     
     protected void setupForRequest(RequestContext context) {
      super.setupForRequest(context);
      Map global = (Map) getGlobal();
      ApplicationContext ac = (ApplicationContext) global.get(APPLICATION_CONTEXT_KEY);
      if (ac == null) {
       ac = WebApplicationContextUtils.getWebApplicationContext(context.getServlet().getServletContext());
      }
      System.out.println("測試" + ac);//你可以看看這一句在什么時候執(zhí)行,從而了解Engine是什么時候被調(diào)用的;
      global.put(APPLICATION_CONTEXT_KEY, ac);
     }
    }

    7、修改tapestry配置文件tshDemo.application,如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE application PUBLIC
      "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
      "
    <!-- generated by Spindle, http://spindle.sourceforge.net -->

    <application name="tshDemo" engine-class="tsh.demo.web.EngineWithSpring">
       
        <description>add a description</description>
       
        <page name="Home" specification-path="Home.page"/>
       
    </application>

    8、修改Home.page文件,如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE page-specification PUBLIC
      "-//Apache Software Foundation//Tapestry Specification 3.0//EN"
      " <!-- generated by Spindle, http://spindle.sourceforge.net -->

    <page-specification class="tsh.demo.web.pages.Home">

        <description>add a description</description>
        <property-specification name="theAction" type="tsh.demo.service.Action" >
         global.appContext.getBean("theAction")
        </property-specification>
        <property-specification name="greeting" type="java.lang.String" />
       
    </page-specification>

    9、Home類,如下:
    /*
     * package tsh.demo.web.pages;
     * class tsh.demo.web.pages.Home
     * Created on 2006-1-24, 10:51:12
     */
    package tsh.demo.web.pages;

    import org.apache.tapestry.event.PageEvent;
    import org.apache.tapestry.event.PageRenderListener;
    import org.apache.tapestry.html.BasePage;

    import tsh.demo.service.Action;

    public abstract class Home extends BasePage implements PageRenderListener {

     public abstract Action getTheAction();
     public abstract void setGreeting(String greeting);
     
     /* (non-Javadoc)
      * @see org.apache.tapestry.event.PageRenderListener#pageBeginRender(org.apache.tapestry.event.PageEvent)
      */
     public void pageBeginRender(PageEvent event) {
      System.out.println(getTheAction().execute("Rod Johnson"));
      setGreeting(getTheAction().execute("Rod Johnson"));
     }
    }

    10、Home.html文件,如下:
    <html jwcid="@Shell" title="application">
    <head></head>
    <body>
       <h3>welcome, </h3><h1><span jwcid="@Insert" value="ognl:greeting" /></h1>
    </body>
    </html>

    11、相關(guān)spring bean 類如下:
    /*
     * package tsh.demo.service;
     * class tsh.demo.service.Action
     * Created on 2005-11-23, 16:32:52
     */
    package tsh.demo.service;

    public interface Action {
     public String execute(String str);
    }

    /*
     * package tsh.demo.service;
     * class tsh.demo.service.LowerAction
     * Created on 2005-11-23, 16:36:32
     */
    package tsh.demo.service;

    public class LowerAction implements Action {
      private String message;
      
      public String getMessage() {
      return message;
      }
     
      public void setMessage(String string) {
       message = string;
      }
     
      public String execute(String str) {
        return (getMessage() + str).toLowerCase();
     }

    }

    /*
     * package tsh.demo.service;
     * class tsh.demo.service.UpperAction
     * Created on 2005-11-23, 16:34:17
     */
    package tsh.demo.service;

    public class UpperAction implements Action {

      private String message;
      
      public String getMessage() {
      return message;
      }
     
      public void setMessage(String string) {
       message = string;
      }
     
      public String execute(String str) {
       return (getMessage() + str).toUpperCase();
      }

    }

    12、在%CATALINA_HOME%\conf\Catalina\localhost目錄下建tshDemo.xml文件,如下:
    <Context path="/tshDemo" docBase="D:\eclipseWorks\workspace\tshDemo\context"
            debug="0" privileged="true" reloadable="true">
      <Logger className="org.apache.catalina.logger.FileLogger"
                 prefix="localhost_Mssql_log." suffix=".txt"
                 timestamp="true"/>

        <!-- maxActive: Maximum number of dB connections in pool. Make sure you
             configure your mysqld max_connections large enough to handle
             all of your db connections. Set to 0 for no limit.
             -->

        <!-- maxIdle: Maximum number of idle dB connections to retain in pool.
             Set to -1 for no limit.  See also the DBCP documentation on this
             and the minEvictableIdleTimeMillis configuration parameter.
             -->

        <!-- maxWait: Maximum time to wait for a dB connection to become available
             in ms, in this example 10 seconds. An Exception is thrown if
             this timeout is exceeded.  Set to -1 to wait indefinitely.
             -->

        <!-- username and password: MySQL dB username and password for dB connections  -->

        <!-- driverClassName: Class name for the old mm.mysql JDBC driver is
             org.gjt.mm.mysql.Driver - we recommend using Connector/J though.
             Class name for the official MySQL Connector/J driver is com.mysql.jdbc.Driver.
             -->
       
        <!-- url: The JDBC connection url for connecting to your MySQL dB.
             The autoReconnect=true argument to the url makes sure that the
             mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
             connection.  mysqld by default closes idle connections after 8 hours.
             -->
      <!--Resource name="jdbc/m2Base" auth="Container" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000"
        url="jdbc:jtds:sqlserver://im04:1433;DatabaseName=m2Base"
        username="xxxx" password="xxxxxxxxx" driverClassName="net.sourceforge.jtds.jdbc.Driver"
        removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true" />

      <Resource name="jdbc/merp" auth="Container" type="javax.sql.DataSource"
        maxActive="100" maxIdle="30" maxWait="10000"
        url="jdbc:jtds:sqlserver://im04:1433;DatabaseName=merp"
        username="xxxxxxx" password="xxxxxxxxx" driverClassName="net.sourceforge.jtds.jdbc.Driver"
        removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true" /-->

    </Context>


    /**
     * Hibernate的集成日后補充
     **/
    66、啟動tomcat,訪問http://locahost:8080/tshDemo,如果頁面正常顯示,配置成功。

    posted on 2008-10-04 23:49 Blog of JoJo 閱讀(1095) 評論(1)  編輯  收藏 所屬分類: Programming 相關(guān)

    FeedBack:
    # re: tsh Tapestry Spring Hibernate 集成筆記
    2008-10-05 23:13 | Blog of JoJo
    一本很好的是Enjoying Web Development with Tapestry,非常的棒,由淺入深,可惜目前無法找全這本書,http://www.itpub.net/390564.html有前4章。  回復(fù)  更多評論
      

    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 无码日韩精品一区二区免费| 中文字幕的电影免费网站| 最近2019免费中文字幕视频三| 亚洲综合无码AV一区二区| 国产精品午夜免费观看网站| 亚洲精品一级无码中文字幕| 国产精品亚洲а∨无码播放麻豆| 国产免费131美女视频| 久久精品国产亚洲AV| 免费a级毛片无码a∨性按摩| 美女视频黄频a免费| 亚洲日本一区二区三区在线不卡| 成人片黄网站色大片免费观看cn| 亚洲AV永久青草无码精品| 免费人成毛片动漫在线播放| 久久精品九九亚洲精品| 午夜视频在线免费观看| 亚洲婷婷天堂在线综合| 黄网址在线永久免费观看| 亚洲av午夜国产精品无码中文字| 亚洲AV无码乱码精品国产| 两个人www免费高清视频| 亚洲综合久久综合激情久久 | 久久精品国产亚洲AV蜜臀色欲| 免费人成网站在线观看10分钟| 亚洲一区二区无码偷拍| 亚洲AV中文无码乱人伦在线视色| caoporn国产精品免费| 亚洲视频日韩视频| 日本大片在线看黄a∨免费| 丰满人妻一区二区三区免费视频| 久久久久亚洲AV无码永不| 免费看无码自慰一区二区| 91在线免费视频| 亚洲jjzzjjzz在线观看| 亚洲国产精品尤物YW在线观看| 久久免费视频精品| 国产亚洲欧美在线观看| 亚洲一级二级三级不卡| 国产大片91精品免费看3| 免费人成网站在线观看不卡|