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

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

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

    Dict.CN 在線詞典, 英語學習, 在線翻譯

    都市淘沙者

    荔枝FM Everyone can be host

    統計

    留言簿(23)

    積分與排名

    優秀學習網站

    友情連接

    閱讀排行榜

    評論排行榜

    tsh Tapestry Spring Hibernate 集成筆記 (轉)

    原文:http://blog.yesky.com/236/javafoot/1209236.shtml

    參考了網上好多文章,記不太清了,在此一并感謝!主要有:
    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開發包(方法是在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);//你可以看看這一句在什么時候執行,從而了解Engine是什么時候被調用的;
      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、相關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 2006-02-26 10:40 都市淘沙者 閱讀(1109) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 久久国产乱子伦精品免费不卡 | 亚洲视频在线一区二区三区| 在线观看免费黄网站| 亚洲日韩乱码中文无码蜜桃臀网站 | 亚洲AV成人噜噜无码网站| 免费成人福利视频| 国产精品亚洲专区在线观看| 在线观看永久免费视频网站| 国产AV日韩A∨亚洲AV电影| 亚洲AV中文无码乱人伦在线视色| 91成人免费观看在线观看| 色婷婷亚洲一区二区三区| 亚洲大尺度无码无码专区| 毛片免费观看网址| 七次郎成人免费线路视频| 亚洲av不卡一区二区三区| 免费看国产精品3a黄的视频| 成年大片免费高清在线看黄| 老汉色老汉首页a亚洲| 一本久到久久亚洲综合| **一级毛片免费完整视| 国产精品亚洲精品日韩电影| 亚洲精品无码久久久久YW| 亚洲综合伊人久久综合| 亚洲免费综合色在线视频| 中文字幕av无码不卡免费| 色偷偷女男人的天堂亚洲网| 亚洲综合图片小说区热久久| 亚洲AV无码乱码精品国产| 免费国产在线观看老王影院| 99精品热线在线观看免费视频| 麻豆亚洲AV成人无码久久精品| 亚洲乱码国产乱码精华| 亚洲av日韩专区在线观看| 久久综合亚洲色一区二区三区| 亚洲成熟xxxxx电影| 亚洲免费视频在线观看| 久久久久久久亚洲精品| 青草草在线视频永久免费| 久久www免费人成看片| 国产免费久久精品99re丫y|