jojo's blog--快樂憂傷都與你同在
          為夢想而來,為自由而生。 性情若水,風起水興,風息水止,故時而激蕩,時又清平……
          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目錄下包含相應jar包,選擇拷貝到目錄


          點擊Finish,完成對spring支持,有一個不好的是,eclipse會把所有的jar包文件一個個明細的列在項目名下,倍長非常不方便,修改辦法,在項目屬性-->Java Build Path-->Libraries中,把所有的明細jar包全部選中刪除,點擊Add Library...-->User Library-->Next> -->勾選相應的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 閱讀(1097) 評論(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章。  回復  更多評論
            

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

          常用鏈接

          留言簿(6)

          隨筆檔案

          文章分類

          文章檔案

          新聞分類

          新聞檔案

          相冊

          收藏夾

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 武汉市| 崇阳县| 南昌县| 宁强县| 平凉市| 邢台县| 白朗县| 舟山市| 宜君县| 定州市| 濮阳县| 博罗县| 武功县| 娄烦县| 锡林浩特市| 东安县| 浪卡子县| 满洲里市| 丹东市| 调兵山市| 竹山县| 阳新县| 肇东市| 柳林县| 磴口县| 中西区| 东方市| 和林格尔县| 平谷区| 合作市| 武城县| 郁南县| 大洼县| 安达市| 贡山| 商丘市| 介休市| 肥东县| 江陵县| 新闻| 青州市|