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

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

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

    Java Home

    Java技術(shù)修煉中...
    posts - 20, comments - 22, trackbacks - 0, articles - 0
      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

    2007年5月15日

    FreeMarker是一個(gè)模板引擎,一個(gè)基于模板生成文本輸出的通用工具,使用純Java編寫

    FreeMarker被設(shè)計(jì)用來(lái)生成HTML Web頁(yè)面,特別是基于MVC模式的應(yīng)用程序

    雖然FreeMarker具有一些編程的能力,但通常由Java程序準(zhǔn)備要顯示的數(shù)據(jù),由FreeMarker生成頁(yè)面,通過(guò)模板顯示準(zhǔn)備的數(shù)據(jù)

    FreeMarker不是一個(gè)Web應(yīng)用框架,而適合作為Web應(yīng)用框架一個(gè)組件

    FreeMarker與容器無(wú)關(guān),因?yàn)樗⒉恢繦TTP或Servlet;FreeMarker同樣可以應(yīng)用于非Web應(yīng)用程序環(huán)境

    FreeMarker更適合作為Model2框架(如Struts)的視圖組件,你也可以在模板中使用JSP標(biāo)記庫(kù)

    FreeMarker是免費(fèi)的

    1、通用目標(biāo)

    能夠生成各種文本:HTML、XML、RTF、Java源代碼等等

    易于嵌入到你的產(chǎn)品中:輕量級(jí);不需要Servlet環(huán)境

    插件式模板載入器:可以從任何源載入模板,如本地文件、數(shù)據(jù)庫(kù)等等

    你可以按你所需生成文本:保存到本地文件;作為Email發(fā)送;從Web應(yīng)用程序發(fā)送它返回給Web瀏覽器

    2、強(qiáng)大的模板語(yǔ)言

    所有常用的指令:include、if/elseif/else、循環(huán)結(jié)構(gòu)

    在模板中創(chuàng)建和改變變量

    幾乎在任何地方都可以使用復(fù)雜表達(dá)式來(lái)指定值

    命名的宏,可以具有位置參數(shù)和嵌套內(nèi)容

    名字空間有助于建立和維護(hù)可重用的宏庫(kù),或者將一個(gè)大工程分成模塊,而不必?fù)?dān)心名字沖突

    輸出轉(zhuǎn)換塊:在嵌套模板片段生成輸出時(shí),轉(zhuǎn)換HTML轉(zhuǎn)義、壓縮、語(yǔ)法高亮等等;你可以定義自己的轉(zhuǎn)換

    3、通用數(shù)據(jù)模型

    FreeMarker不是直接反射到Java對(duì)象,Java對(duì)象通過(guò)插件式對(duì)象封裝,以變量方式在模板中顯示

    你可以使用抽象(接口)方式表示對(duì)象(JavaBean、XML文檔、SQL查詢結(jié)果集等等),告訴模板開發(fā)者使用方法,使其不受技術(shù)細(xì)節(jié)的打擾

    4、為Web準(zhǔn)備

    在模板語(yǔ)言中內(nèi)建處理典型Web相關(guān)任務(wù)(如HTML轉(zhuǎn)義)的結(jié)構(gòu)

    能夠集成到Model2 Web應(yīng)用框架中作為JSP的替代

    支持JSP標(biāo)記庫(kù)

    為MVC模式設(shè)計(jì):分離可視化設(shè)計(jì)和應(yīng)用程序邏輯;分離頁(yè)面設(shè)計(jì)員和程序員

    5、智能的國(guó)際化和本地化

    字符集智能化(內(nèi)部使用UNICODE)

    數(shù)字格式本地化敏感

    日期和時(shí)間格式本地化敏感

    非US字符集可以用作標(biāo)識(shí)(如變量名)

    多種不同語(yǔ)言的相同模板

    6、強(qiáng)大的XML處理能力

    <#recurse> 和<#visit>指令(2.3版本)用于遞歸遍歷XML樹

    在模板中清楚和直覺的訪問(wèn)XML對(duì)象模型

    posted @ 2007-06-19 08:26 Yemoo'S Java Blog 閱讀(497) | 評(píng)論 (0)編輯 收藏

    當(dāng)jsp程序出現(xiàn)異常時(shí),往往是直接輸出到瀏覽器頁(yè)面上的,這樣以來(lái),可能使最終用戶感到不知所措,也可能因?yàn)楸┞斗?wù)器某些信息而導(dǎo)致服務(wù)器的安全性問(wèn)題。在jsp里我們可以通過(guò)制定errorPage="xxx"以使當(dāng)程序出現(xiàn)錯(cuò)誤時(shí)轉(zhuǎn)向指定的錯(cuò)誤頁(yè)面,但如果前期沒有考慮到這個(gè)辦法而在系統(tǒng)完成后再去這些工作則工作量可能會(huì)很大,好在jsp規(guī)范提供了一種簡(jiǎn)單的解決辦法,通過(guò)在web.xml中設(shè)定全局錯(cuò)誤處理頁(yè)面來(lái)對(duì)整個(gè)項(xiàng)目有效,web.xml中對(duì)于不同的http返回結(jié)果或異常類型可以有不同的處理方式。
    在xml中配置如下:
    <error-page>
    ???<error-code>500</error-code>
    ???<location>error.jsp</location>
    </error-page>
    <error-page>
    ???<error-code>404</error-code>
    ???<location>notfound.jsp</location>
    </error-page>

    通過(guò)以上配置,程序會(huì)自動(dòng)根據(jù)錯(cuò)誤類型轉(zhuǎn)向不同的錯(cuò)誤頁(yè)面。

    posted @ 2007-06-06 15:59 Yemoo'S Java Blog 閱讀(1759) | 評(píng)論 (0)編輯 收藏

    前段時(shí)間作了一個(gè)簡(jiǎn)單的系統(tǒng),其中涉及到后臺(tái)管理,當(dāng)然也就遇到了權(quán)限驗(yàn)證的問(wèn)題,由于初次做J2EE項(xiàng)目,所有這些東西懂我來(lái)說(shuō)都是個(gè)開始。
    對(duì)于權(quán)限驗(yàn)證,如果程序由目錄劃分,如管理員訪問(wèn)的頁(yè)面都放在admin下,這樣我們可以寫一個(gè)權(quán)限驗(yàn)證的過(guò)濾器,然后配置admin目錄都要經(jīng)過(guò)這個(gè)過(guò)濾器即可。這樣對(duì)于jsp頁(yè)面的權(quán)限驗(yàn)證比較容易。但對(duì)于action(控制器類)就不好控制了,因?yàn)閍ction是沒有目錄概念的,如我們?cè)L問(wèn)action的地址為:http://xxx/sample/ac1.action,同時(shí)如果使用http://xxx/sample/xx/xx/ac1.action同樣可以訪問(wèn),這是因?yàn)橹灰谶@個(gè)項(xiàng)目目錄下,訪問(wèn)的頁(yè)面如果為action則struts就會(huì)去查詢這個(gè)action名字對(duì)應(yīng)的類,而不管前面的目錄結(jié)構(gòu)。因此我們不能再用過(guò)濾器對(duì)管理員部分的action進(jìn)行驗(yàn)證。經(jīng)過(guò)查看struts2的相關(guān)資料發(fā)現(xiàn)了攔截器這個(gè)有用的東西。通過(guò)struts2的配置文件的包管理功能和攔截器可以輕松的對(duì)指定的action做管理(攔截),如
    ===================================================
    <package name="user" extends="struts-default">
    ??<!-- 前臺(tái)用戶操作部分 -->
    ??<!-- 框架頁(yè),顯示分類 -->
    ??<action name="queryCateForwardUI"
    ???class="com.topsoft.bookmanage.web.action.QueryCateForwardActionUI">
    ???<result>/mainPage.jsp</result>
    ??</action>
    ??? 。。。。。
    </package>
    <!-- 管理員操作部分 -->
    ?<package name="manager" extends="struts-default">
    ??<!-- 攔截器 -->
    ??<interceptors>
    ???<interceptor name="auth" class="com.topsoft.common.LogonInterceptor" />
    ???<interceptor-stack name="authStack">?
    ??????????????? <interceptor-ref name="auth"/>?
    ??????????????? <interceptor-ref name="paramsPrepareParamsStack"/>?
    ??????????? </interceptor-stack>?
    ??</interceptors>
    ??<!-- 默認(rèn)執(zhí)行的攔截器 -->
    ??<default-interceptor-ref name="authStack"/>
    ??<!-- 全局Action映射 -->
    ??<global-results>
    ???<result name="login" type="redirect">/managerLoginUI.action</result>
    ??</global-results>
    ??
    ??<!-- 后臺(tái)管理首頁(yè)面UI -->
    ??<action name="managerIndexUI"
    ???class="com.topsoft.bookmanage.web.action.ManagerIndexActionUI">
    ???<result>/admin/index.jsp</result>
    ??</action>
    ?。。。。。。
    </package>
    =================================================

    通過(guò)使用攔截器+過(guò)濾器可以完美解決權(quán)限驗(yàn)證的問(wèn)題。

    posted @ 2007-06-06 15:17 Yemoo'S Java Blog 閱讀(4978) | 評(píng)論 (6)編輯 收藏

    struts.action.extension
    ????????? The URL extension to use to determine if the request is meant for a Struts action
    ?????????? 用URL擴(kuò)展名來(lái)確定是否這個(gè)請(qǐng)求是被用作Struts action,其實(shí)也就是設(shè)置 action的后綴,例如login.do的'do'字。

    struts.configuration
    ????????? The org.apache.struts2.config.Configuration implementation class
    ??????????? org.apache.struts2.config.Configuration接口名

    struts.configuration.files
    ????????? A list of configuration files automatically loaded by Struts
    ?????????? struts自動(dòng)加載的一個(gè)配置文件列表

    struts.configuration.xml.reload
    ????????? Whether to reload the XML configuration or not
    ?????????? 是否加載xml配置(true,false)

    struts.continuations.package
    ?????????? The package containing actions that use Rife continuations
    ?????????? 含有actions的完整連續(xù)的package名稱

    struts.custom.i18n.resources
    ????????? Location of additional localization properties files to load
    ?????????? 加載附加的國(guó)際化屬性文件(不包含.properties后綴)

    struts.custom.properties
    ????????? Location of additional configuration properties files to load
    ?????????? 加載附加的配置文件的位置


    struts.devMode
    ????????? Whether Struts is in development mode or not
    ?????????? 是否為struts開發(fā)模式

    struts.dispatcher.parametersWorkaround
    ????????? Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic
    ??????????? (某些版本的weblogic專用)是否使用一個(gè)servlet請(qǐng)求參數(shù)工作區(qū)(PARAMETERSWORKAROUND)

    struts.enable.DynamicMethodInvocation
    ????????? Allows one to disable dynamic method invocation from the URL
    ??????????? 允許動(dòng)態(tài)方法調(diào)用

    struts.freemarker.manager.classname
    ????????? The org.apache.struts2.views.freemarker.FreemarkerManager implementation class
    ?????????? org.apache.struts2.views.freemarker.FreemarkerManager接口名

    struts.i18n.encoding
    ????????? The encoding to use for localization messages
    ?????????? 國(guó)際化信息內(nèi)碼

    struts.i18n.reload
    ????????? Whether the localization messages should automatically be reloaded
    ?????????? 是否國(guó)際化信息自動(dòng)加載

    struts.locale
    ????????? The default locale for the Struts application
    ?????????? 默認(rèn)的國(guó)際化地區(qū)信息

    struts.mapper.class
    ????????? The org.apache.struts2.dispatcher.mapper.ActionMapper implementation class
    ??????????? org.apache.struts2.dispatcher.mapper.ActionMapper接口

    struts.multipart.maxSize
    ????????? The maximize size of a multipart request (file upload)
    ?????????? multipart請(qǐng)求信息的最大尺寸(文件上傳用)

    struts.multipart.parser
    ????????? The org.apache.struts2.dispatcher.multipart.MultiPartRequest parser implementation for a multipart request (file upload)
    ????????? 專為multipart請(qǐng)求信息使用的org.apache.struts2.dispatcher.multipart.MultiPartRequest解析器接口(文件上傳用)


    struts.multipart.saveDir
    ????????? The directory to use for storing uploaded files
    ?????????? 設(shè)置存儲(chǔ)上傳文件的目錄夾

    struts.objectFactory
    ????????? The com.opensymphony.xwork2.ObjectFactory implementation class
    ?????????? com.opensymphony.xwork2.ObjectFactory接口(spring)

    struts.objectFactory.spring.autoWire
    ????????? Whether Spring should autoWire or not
    ?????????? 是否自動(dòng)綁定Spring

    struts.objectFactory.spring.useClassCache
    ????????? Whether Spring should use its class cache or not
    ?????????? 是否spring應(yīng)該使用自身的cache

    struts.objectTypeDeterminer
    ????????? The com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation class
    ??????????? com.opensymphony.xwork2.util.ObjectTypeDeterminer接口

    struts.serve.static.browserCache
    ????????? If static content served by the Struts filter should set browser caching header properties or not
    ?????????? 是否struts過(guò)濾器中提供的靜態(tài)內(nèi)容應(yīng)該被瀏覽器緩存在頭部屬性中

    struts.serve.static
    ????????? Whether the Struts filter should serve static content or not
    ?????????? 是否struts過(guò)濾器應(yīng)該提供靜態(tài)內(nèi)容

    struts.tag.altSyntax
    ????????? Whether to use the alterative syntax for the tags or not
    ?????????? 是否可以用替代的語(yǔ)法替代tags

    struts.ui.templateDir
    ????????? The directory containing UI templates
    ?????????? UI templates的目錄夾

    struts.ui.theme
    ????????? The default UI template theme
    ?????????? 默認(rèn)的UI template主題

    struts.url.http.port
    ????????? The HTTP port used by Struts URLs
    ?????????? 設(shè)置http端口

    struts.url.https.port
    ????????? The HTTPS port used by Struts URLs
    ?????????? 設(shè)置https端口

    struts.url.includeParams
    ????????? The default includeParams method to generate Struts URLs
    ????????? 在url中產(chǎn)生 默認(rèn)的includeParams


    struts.velocity.configfile
    ????????? The Velocity configuration file path
    ?????????? velocity配置文件路徑

    struts.velocity.contexts
    ????????? List of Velocity context names
    ?????????? velocity的context列表


    struts.velocity.manager.classname
    ????????? org.apache.struts2.views.velocity.VelocityManager implementation class
    ?????????? org.apache.struts2.views.velocity.VelocityManager接口名

    struts.velocity.toolboxlocation
    ????????? The location of the Velocity toolbox
    ?????????? velocity工具盒的位置
    struts.xslt.nocache
    ????????? Whether or not XSLT templates should not be cached
    ?????????? 是否XSLT模版應(yīng)該被緩存

    posted @ 2007-05-20 19:05 Yemoo'S Java Blog 閱讀(543) | 評(píng)論 (0)編輯 收藏

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "

    <beans>

    ??建立一個(gè)數(shù)據(jù)源
    ?<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    ? <property name="driverClassName">
    ?? <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
    ? </property>
    ? <property name="url">
    ?? <value>jdbc:microsoft:sqlserver://192.168.0.6:1433</value>
    ? </property>
    ? <property name="username">
    ?? <value>sa</value>
    ? </property>
    ? <property name="password">
    ?? <value></value>
    ? </property>
    ?</bean>

    ? 建立會(huì)話工廠類,這個(gè)類使用spring專門為hibernate3提供LocalSessionFactoryBean
    ?
    ?<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    ? <property name="dataSource">
    ?? <ref local="dataSource" />? --引用上面的數(shù)據(jù)源
    ? </property>
    ? <property name="mappingResources">? --調(diào)入映射文檔
    ?? <list>
    ??? <value>com/yourcompany/User.hbm.xml</value>?
    ?? </list>
    ? </property>
    ? <property name="hibernateProperties">? --相關(guān)設(shè)置
    ?? <props>
    ??? <prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
    ??? <prop key="hibernate.show_sql">true</prop>
    ?? </props>
    ? </property>
    ?</bean>
    ??

    ??? 定義事務(wù)管理器,這個(gè)也是 spring專門為hibernate3提供的HibernateTransactionManager 事務(wù)管理器
    ?<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
    ? <property name="sessionFactory">
    ?? <ref local="sessionFactory" />?? --引用會(huì)話工廠類
    ? </property>
    ?</bean>

    ?定義實(shí)體DAO
    ?<bean id="userDAO" class="com.yourcompany.UserDAOImp">
    ? <property name="sessionFactory">
    ?? <ref local="sessionFactory" />--引用會(huì)話工廠類
    ? </property>
    ?</bean>
    ?

    ?為上面的實(shí)體DAO定義一個(gè)代理(proxy)類,這是spring為解決事務(wù)問(wèn)題而提供TransactionProxyFactoryBean動(dòng)態(tài)事務(wù)代理類
    ?<bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    ? <property name="transactionManager">
    ?? <ref bean="transactionManager" />? --指定事務(wù)管理器(需要是spring專用的)
    ? </property>
    ? <property name="target"> --目標(biāo)實(shí)體DAO類
    ?? <ref local="userDAO" />
    ? </property>
    ? <property name="transactionAttributes"> --定義要使用事務(wù)的方法
    ?? <props>
    ??? <prop key="insert*">PROPAGATION_REQUIRED</prop>? --所有insert開頭的方法都使用事務(wù),出錯(cuò)要回滾
    ??? <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop> --所有g(shù)et開頭的方法都使用只讀事務(wù)
    ??? <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>--所有ist開頭的方法都使用只讀事務(wù)
    ?? </props>
    ? </property>
    ?</bean>

    ??為 path="/login"?的struts action 定義實(shí)際的action類,該action?已經(jīng)進(jìn)行?type="org.springframework.web.struts.DelegatingActionProxy"設(shè)置
    ? <bean name="/login" class="com.yourcompany.struts.action.LoginAction" singleton="false">
    ??? <property name="userDAO">
    ??? <ref bean="userDAOProxy" />? --注意,這里指定的userDAO是上面定義的代理類
    ? </property>
    ?</bean>
    </beans>?

    posted on 2006-12-05 15:40 kelven 閱讀(1

    posted @ 2007-05-15 08:21 Yemoo'S Java Blog 閱讀(417) | 評(píng)論 (0)編輯 收藏

    主站蜘蛛池模板: 国产aa免费视频| 亚洲av永久无码制服河南实里| 人妻巨大乳hd免费看| 亚洲人AV永久一区二区三区久久| A级毛片成人网站免费看| 亚洲欧洲精品一区二区三区| 全免费a级毛片免费看不卡| aa级毛片毛片免费观看久| 亚洲春色另类小说| 内射无码专区久久亚洲| 久久久久久国产精品免费免费男同 | 在线看片韩国免费人成视频| 亚洲AV成人影视在线观看| 亚洲午夜日韩高清一区| 1000部拍拍拍18勿入免费凤凰福利| 久久久久亚洲AV无码去区首| 亚洲第一极品精品无码久久| 青青青青青青久久久免费观看 | 久久久久国色AV免费看图片| 九九九精品视频免费| 亚洲欧洲日本天天堂在线观看| 免费真实播放国产乱子伦| 一级毛片免费视频| 九九视频高清视频免费观看| 亚洲福利一区二区| 亚洲综合色区在线观看| 丁香花在线观看免费观看| 一个人看的www免费视频在线观看| 亚洲中文字幕久久精品蜜桃| 亚洲av中文无码乱人伦在线r▽| 国产国产人免费视频成69大陆| 亚洲日本在线免费观看| a级片免费在线观看| 日韩色视频一区二区三区亚洲| 亚洲最大免费视频网| 久久精品国产69国产精品亚洲| 日本免费一区二区三区最新vr| 69视频在线观看高清免费| 亚欧洲精品在线视频免费观看| 亚洲AV色欲色欲WWW| 亚洲AV无码成人专区|