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

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

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

    Java Blog for Alex Wan

    Let life be beautiful like summer flowers and death like autumn leaves.

    統(tǒng)計(jì)

    留言簿(10)

    BlogJava

    Blogs

    DIV+CSS

    JQuery相關(guān)

    友情鏈接

    常去的地方

    數(shù)據(jù)供應(yīng)

    閱讀排行榜

    評(píng)論排行榜

    在appfuse構(gòu)建的項(xiàng)目中集成velocity的步驟和碰到的問題

    使用Velocity無(wú)非也就是為了能夠真正的實(shí)現(xiàn)mvc分層,使得各個(gè)團(tuán)隊(duì)成員(美工,程序員)可以各盡所長(zhǎng)。

    在appfuse構(gòu)建的項(xiàng)目中集成velocity的步驟和碰到的問題 :

    1:修改web.xml使得項(xiàng)目支持velocity

    (1)定義名為velocity的servlet:

    <servlet>
            
    <servlet-name>velocity</servlet-name>
            
    <servlet-class>
                org.apache.velocity.tools.view.servlet.VelocityViewServlet
            
    </servlet-class>
            
    <init-param>
                
    <param-name>org.apache.velocity.toolbox</param-name>
                
    <param-value>/WEB-INF/toolbox.xml</param-value>
            
    </init-param>
            
    <init-param>
                
    <param-name>org.apache.velocity.properties</param-name>
                
    <param-value>
                    /WEB-INF/classes/velocity.properties
                
    </param-value>
            
    </init-param>
            
    <load-on-startup>10</load-on-startup>
        
    </servlet>

    (2)定義對(duì)應(yīng)velocity的servlet-mapping:

      <servlet-mapping>
            
    <servlet-name>velocity</servlet-name>
            
    <url-pattern>*.vm</url-pattern>
        
    </servlet-mapping>

    (3)將velocity納入到編碼過濾的filter(一般都已經(jīng)定義經(jīng)典SetCharacterEncoding):

     <filter-mapping>
            
    <filter-name>SetCharacterEncoding</filter-name>
            
    <url-pattern>*.vm</url-pattern>
        
    </filter-mapping>
    2:在項(xiàng)目的web/WEB-INF文件夾中創(chuàng)建并編輯文件toolbox.xml,通常的內(nèi)容如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <toolbox>
      
    <tool>
         
    <key>link</key>
         
    <scope>request</scope>
         
    <class>org.apache.velocity.tools.struts.StrutsLinkTool</class>
      
    </tool>
      
    <tool>
         
    <key>text</key>
         
    <scope>request</scope>
         
    <class>org.apache.velocity.tools.struts.MessageTool</class>
      
    </tool>
      
    <tool>
         
    <key>errors</key>
         
    <scope>request</scope>
         
    <class>org.apache.velocity.tools.struts.ErrorsTool</class>
      
    </tool>
      
    <tool>
         
    <key>form</key>
         
    <scope>request</scope>
         
    <class>org.apache.velocity.tools.struts.FormTool</class>
      
    </tool>
      
    <tool>
         
    <key>tiles</key>
         
    <scope>request</scope>
         
    <class>org.apache.velocity.tools.struts.TilesTool</class>
      
    </tool>
      
    <tool>
         
    <key>validator</key>
         
    <scope>request</scope>
         
    <class>org.apache.velocity.tools.struts.ValidatorTool</class>
      
    </tool>
    </toolbox>

    3:在項(xiàng)目的build/web/classes文件夾中創(chuàng)建并編輯文件velocity.properties,通常的內(nèi)容:
    input.encoding = UTF-8
    #out.encoding = UTF-8
    default.contentType=text/html; charset=UTF-8

    ---以上三步其實(shí)就是普通java web項(xiàng)目集成velocity的必須要做的工作了。
    ---下面是使用appfuse中的appgen生成velocity代碼的要做的工作,這里只做了從table出發(fā)的生成過程。

    4:在項(xiàng)目中extras/appgen/src中創(chuàng)建模板,這里假設(shè)創(chuàng)建的兩個(gè)文件是List_vm.xdt和Form_vm.xdt
    模板的具體內(nèi)容就要結(jié)合xdoclet,velocity和html來(lái)編寫,不是一個(gè)簡(jiǎn)單的工作!

    5:編輯extras/appgen下的build.xml文件,使得在使用ant install-detailed的時(shí)候能生成數(shù)據(jù)表對(duì)應(yīng)的vm文件.

    (1):在名為gen的target中添加template,原文件有以下的代碼:


    <!-- Form JSP -->
                
    <template templateFile="${template.dir}/Form_jsp.xdt"
                          acceptAbstractClasses
    ="false"
                          prefixWithPackageStructure
    ="false"
                          destinationFile
    ="${gen.dir}/web/pages/{0}FormTemp.jsp"/>
                
    <!-- List JSP -->
                
    <template templateFile="${template.dir}/List_jsp.xdt"
                          acceptAbstractClasses
    ="false"
                          prefixWithPackageStructure
    ="false"
                          destinationFile
    ="${gen.dir}/web/pages/{0}ListTemp.jsp"/>
    我們要在這個(gè)后面添加以下代碼(如果不使用jsp作為view層可以使用替換的方式把原文件的這部分內(nèi)容處理掉):
    <!-- Form VM -->
                
    <template templateFile="${template.dir}/Form_vm.xdt"
                  acceptAbstractClasses
    ="false"
                  prefixWithPackageStructure
    ="false"
                  destinationFile
    ="${gen.dir}/web/vms/{0}FormTemp.vm"/>
                
    <!-- List VM -->
                   
    <template templateFile="${template.dir}/List_VM.xdt"
                  acceptAbstractClasses
    ="false"
                  prefixWithPackageStructure
    ="false"
                  destinationFile
    ="${gen.dir}/web/vms/{0}ListTemp.vm"/>

    這里,templateFile里指定模板文件,destinationFile指定生成的臨時(shí)文件。

    (2):在名字同樣為gen的target中添加move任務(wù),原文件中有以下代碼:


    <!-- Make first character of JSP filenames lowercase -->
            
    <move file="${build.dir}/${gen.dir}/web/pages/${model.name}ListTemp.jsp"
                tofile
    ="${build.dir}/${gen.dir}/web/pages/${app.module.slash.after}${model.name.lowercase}List.jsp"/>
            
    <move file="${build.dir}/${gen.dir}/web/pages/${model.name}FormTemp.jsp"
                tofile
    ="${build.dir}/${gen.dir}/web/pages/${app.module.slash.after}${model.name.lowercase}Form.jsp"/>

    我們要在這個(gè)后面添加以下代碼(如果不使用jsp作為view層可以使用替換的方式把原文件的這部分內(nèi)容處理掉):
    <!-- Make first character of Velocity filenames lowercase -->
            
    <move file="${build.dir}/${gen.dir}/web/vms/${model.name}ListTemp.vm"
                tofile
    ="${build.dir}/${gen.dir}/web/vms/${app.module.slash.after}${model.name.lowercase}List.vm"/>
            
    <move file="${build.dir}/${gen.dir}/web/vms/${model.name}FormTemp.vm"
                tofile
    ="${build.dir}/${gen.dir}/web/vms/${app.module.slash.after}${model.name.lowercase}Form.vm"/>

    這樣生成的臨時(shí)文件就會(huì)被重命名(有點(diǎn)懷疑這樣做的必要性,暫且先這樣做吧)。

    (3):在名為merge-common的target中添加copy任務(wù),原文件中有如下代碼


      <!-- copy jsp files -->
            
    <echo>Copying all web files into main project, overwrite="${overwrite}"</echo>
            
    <copy todir="../../web/pages">
                
    <fileset dir="${generated.dir}/web/pages" includes="**/${model.name.lowercase}*.jsp"/>
            
    </copy>

    我們要在這個(gè)后面添加以下代碼(如果不使用jsp作為view層可以使用替換的方式把原文件的這部分內(nèi)容處理掉):
     <!-- copy velocity files -->
            
    <echo>Copying all velocity files into main project, overwrite="${overwrite}"</echo>
            
    <copy todir="../../web/vms">
                
    <fileset dir="${generated.dir}/web/vms" includes="**/${model.name.lowercase}*.vm"/>
            
    </copy>

    這樣在使用ant install-detailed命令時(shí)就會(huì)把生成的文件復(fù)制到項(xiàng)目的web/vms文件夾下了。

    7:修改項(xiàng)目的根目錄下的build.xml:

    (1)修改名為copy-web-files的target,使得運(yùn)行ant deploy時(shí)可以將vm文件復(fù)制到部署項(xiàng)目的WEB-INFO文件夾下(放在WEB-INF下是為了防止直接訪問 )。
    參考的源代碼:


     <!-- Copy JSP Pages under WEB-INF/pages -->
            
    <copy todir="${webapp.target}/WEB-INF">
                
    <fileset dir="${basedir}/web">
                    
    <include name="pages/**/*.jsp"/>
                
    </fileset>
                
    <fileset dir="${struts.dir}" includes="*.xml"/>
                
    <fileset dir="${basedir}/web/WEB-INF" includes="**/*-resources.xml"/>
                
    <filterset refid="db.variables"/>
            
    </copy>

    可以在這個(gè)任務(wù)后面添加一個(gè)任務(wù):
    <fileset dir="${basedir}/web">
                    
    <include name="vms/**/*.vm"/>
                
    </fileset>

    另外,如果不再使用jsp做為view層可以把匹配jsp的fileset節(jié)點(diǎn)去掉,這樣就不會(huì)復(fù)制多余的文件到部署的項(xiàng)目中了。

    (2)同名的target 中修改另外一個(gè)copy任務(wù)(順數(shù)第二個(gè)),源代碼:

     <copy todir="${webapp.target}" includeEmptyDirs="no">
                
    <fileset dir="${basedir}/web">
                    
    <include name="**"/>
                    
    <exclude name="pages/**"/>
                    
    <exclude name="**/classes/**"/>
                    
    <exclude name="**/*-resources.xml"/>
                
    </fileset>
            
    </copy>

    在fileset中添加一個(gè)節(jié)點(diǎn):
    <exclude name="vms/**"/>

    這樣就不會(huì)把vms文件夾下的文件當(dāng)成是普通文件那樣復(fù)制了

    8:在struts-config.xml修改forwards,使得它們指向特定的vm。

    ps:基本上就是這么多的步驟,遺漏的地方,歡迎補(bǔ)充!



    Let life be beautiful like summer flowers and death like autumn leaves.

    posted on 2008-06-07 09:54 Alexwan 閱讀(529) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 国产精品无码免费专区午夜| 日韩黄色免费观看| 一二三四视频在线观看中文版免费 | 黄网站免费在线观看| 国产亚洲欧美日韩亚洲中文色| 亚洲综合久久综合激情久久| 亚洲午夜无码AV毛片久久| 扒开双腿猛进入爽爽免费视频| 99爱在线精品视频免费观看9| 人与动性xxxxx免费| 国产精品国产亚洲区艳妇糸列短篇| 亚洲精品美女在线观看播放| 九月丁香婷婷亚洲综合色| 亚洲A∨午夜成人片精品网站| 污污视频免费观看网站| 亚洲第一男人天堂| 亚洲国产一区在线观看| 亚洲日本va午夜中文字幕一区| 亚洲午夜精品第一区二区8050| 免费国产怡红院在线观看| 成人毛片18女人毛片免费96| 我的小后妈韩剧在线看免费高清版| 七色永久性tv网站免费看| 91视频精品全国免费观看| ww在线观视频免费观看w| 久久久婷婷五月亚洲97号色 | 一个人免费观看日本www视频| 亚洲高清毛片一区二区| 亚洲成a人片在线观看精品| 亚洲无码高清在线观看| yy6080久久亚洲精品| 在线永久免费观看黄网站| 日韩免费一区二区三区| 日韩人妻无码免费视频一区二区三区 | 日本不卡免费新一区二区三区 | 亚洲av综合avav中文| 久久亚洲精品成人| 亚洲韩国—中文字幕| 久久亚洲精品成人无码网站| 久久久久亚洲AV无码网站| 亚洲精品中文字幕乱码影院 |