<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 閱讀(1094) 評論(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ù)  更多評論
      

    <2008年10月>
    2829301234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    常用鏈接

    留言簿(6)

    隨筆檔案

    文章分類

    文章檔案

    新聞分類

    新聞檔案

    相冊

    收藏夾

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 国内精品99亚洲免费高清| 亚洲区精品久久一区二区三区| 成全高清在线观看免费| 久久亚洲sm情趣捆绑调教| 性感美女视频免费网站午夜| 一级片在线免费看| 99久久亚洲综合精品成人网| 免费一级特黄特色大片在线观看| 免费精品99久久国产综合精品| 一本色道久久88亚洲精品综合| 久久精品国产亚洲7777| 亚洲免费综合色在线视频| 久香草视频在线观看免费| 亚洲成a人片在线观| 亚洲日韩精品无码专区网站 | 一级看片免费视频| 亚洲成人免费在线观看| 国产偷窥女洗浴在线观看亚洲 | 亚洲高清免费在线观看| 一级毛片a免费播放王色电影| 亚洲欧洲国产成人精品| 亚洲VA综合VA国产产VA中| 曰曰鲁夜夜免费播放视频| 巨胸狂喷奶水视频www网站免费| 亚洲va在线va天堂成人| 亚洲精品制服丝袜四区| 日韩成全视频观看免费观看高清| 免费精品一区二区三区第35| 青青草97国产精品免费观看| 国产.亚洲.欧洲在线| 亚洲国产第一页www| 日日噜噜噜噜夜夜爽亚洲精品| 国产裸模视频免费区无码| 3344免费播放观看视频| 三年片在线观看免费| 日日狠狠久久偷偷色综合免费| 亚洲午夜理论片在线观看| 久久久久亚洲av无码专区| 亚洲成AV人片在线观看WWW| 亚洲人成无码网站久久99热国产| 国产免费怕怕免费视频观看|