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

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

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

    Java Home

    Java技術修煉中...
    posts - 20, comments - 22, trackbacks - 0, articles - 0
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    2006年12月7日

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

    FreeMarker被設計用來生成HTML Web頁面,特別是基于MVC模式的應用程序

    雖然FreeMarker具有一些編程的能力,但通常由Java程序準備要顯示的數據,由FreeMarker生成頁面,通過模板顯示準備的數據

    FreeMarker不是一個Web應用框架,而適合作為Web應用框架一個組件

    FreeMarker與容器無關,因為它并不知道HTTP或Servlet;FreeMarker同樣可以應用于非Web應用程序環境

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

    FreeMarker是免費的

    1、通用目標

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

    易于嵌入到你的產品中:輕量級;不需要Servlet環境

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

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

    2、強大的模板語言

    所有常用的指令:include、if/elseif/else、循環結構

    在模板中創建和改變變量

    幾乎在任何地方都可以使用復雜表達式來指定值

    命名的宏,可以具有位置參數和嵌套內容

    名字空間有助于建立和維護可重用的宏庫,或者將一個大工程分成模塊,而不必擔心名字沖突

    輸出轉換塊:在嵌套模板片段生成輸出時,轉換HTML轉義、壓縮、語法高亮等等;你可以定義自己的轉換

    3、通用數據模型

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

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

    4、為Web準備

    在模板語言中內建處理典型Web相關任務(如HTML轉義)的結構

    能夠集成到Model2 Web應用框架中作為JSP的替代

    支持JSP標記庫

    為MVC模式設計:分離可視化設計和應用程序邏輯;分離頁面設計員和程序員

    5、智能的國際化和本地化

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

    數字格式本地化敏感

    日期和時間格式本地化敏感

    非US字符集可以用作標識(如變量名)

    多種不同語言的相同模板

    6、強大的XML處理能力

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

    在模板中清楚和直覺的訪問XML對象模型

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

    當jsp程序出現異常時,往往是直接輸出到瀏覽器頁面上的,這樣以來,可能使最終用戶感到不知所措,也可能因為暴露服務器某些信息而導致服務器的安全性問題。在jsp里我們可以通過制定errorPage="xxx"以使當程序出現錯誤時轉向指定的錯誤頁面,但如果前期沒有考慮到這個辦法而在系統完成后再去這些工作則工作量可能會很大,好在jsp規范提供了一種簡單的解決辦法,通過在web.xml中設定全局錯誤處理頁面來對整個項目有效,web.xml中對于不同的http返回結果或異常類型可以有不同的處理方式。
    在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>

    通過以上配置,程序會自動根據錯誤類型轉向不同的錯誤頁面。

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

    前段時間作了一個簡單的系統,其中涉及到后臺管理,當然也就遇到了權限驗證的問題,由于初次做J2EE項目,所有這些東西懂我來說都是個開始。
    對于權限驗證,如果程序由目錄劃分,如管理員訪問的頁面都放在admin下,這樣我們可以寫一個權限驗證的過濾器,然后配置admin目錄都要經過這個過濾器即可。這樣對于jsp頁面的權限驗證比較容易。但對于action(控制器類)就不好控制了,因為action是沒有目錄概念的,如我們訪問action的地址為:http://xxx/sample/ac1.action,同時如果使用http://xxx/sample/xx/xx/ac1.action同樣可以訪問,這是因為只要在這個項目目錄下,訪問的頁面如果為action則struts就會去查詢這個action名字對應的類,而不管前面的目錄結構。因此我們不能再用過濾器對管理員部分的action進行驗證。經過查看struts2的相關資料發現了攔截器這個有用的東西。通過struts2的配置文件的包管理功能和攔截器可以輕松的對指定的action做管理(攔截),如
    ===================================================
    <package name="user" extends="struts-default">
    ??<!-- 前臺用戶操作部分 -->
    ??<!-- 框架頁,顯示分類 -->
    ??<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>
    ??<!-- 默認執行的攔截器 -->
    ??<default-interceptor-ref name="authStack"/>
    ??<!-- 全局Action映射 -->
    ??<global-results>
    ???<result name="login" type="redirect">/managerLoginUI.action</result>
    ??</global-results>
    ??
    ??<!-- 后臺管理首頁面UI -->
    ??<action name="managerIndexUI"
    ???class="com.topsoft.bookmanage.web.action.ManagerIndexActionUI">
    ???<result>/admin/index.jsp</result>
    ??</action>
    ?。。。。。。
    </package>
    =================================================

    通過使用攔截器+過濾器可以完美解決權限驗證的問題。

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

    struts.action.extension
    ????????? The URL extension to use to determine if the request is meant for a Struts action
    ?????????? 用URL擴展名來確定是否這個請求是被用作Struts action,其實也就是設置 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自動加載的一個配置文件列表

    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的完整連續的package名稱

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

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


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

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

    struts.enable.DynamicMethodInvocation
    ????????? Allows one to disable dynamic method invocation from the URL
    ??????????? 允許動態方法調用

    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
    ?????????? 國際化信息內碼

    struts.i18n.reload
    ????????? Whether the localization messages should automatically be reloaded
    ?????????? 是否國際化信息自動加載

    struts.locale
    ????????? The default locale for the Struts application
    ?????????? 默認的國際化地區信息

    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請求信息的最大尺寸(文件上傳用)

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


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

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

    struts.objectFactory.spring.autoWire
    ????????? Whether Spring should autoWire or not
    ?????????? 是否自動綁定Spring

    struts.objectFactory.spring.useClassCache
    ????????? Whether Spring should use its class cache or not
    ?????????? 是否spring應該使用自身的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過濾器中提供的靜態內容應該被瀏覽器緩存在頭部屬性中

    struts.serve.static
    ????????? Whether the Struts filter should serve static content or not
    ?????????? 是否struts過濾器應該提供靜態內容

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

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

    struts.ui.theme
    ????????? The default UI template theme
    ?????????? 默認的UI template主題

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

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

    struts.url.includeParams
    ????????? The default includeParams method to generate Struts URLs
    ????????? 在url中產生 默認的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模版應該被緩存

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

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

    <beans>

    ??建立一個數據源
    ?<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>

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

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

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

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

    ??為 path="/login"?的struts action 定義實際的action類,該action?已經進行?type="org.springframework.web.struts.DelegatingActionProxy"設置
    ? <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) | 評論 (0)編輯 收藏

    今天把jdk從1.6.0卸載后又安裝了1.5.04,然后發現netbeans無法啟動,提示“Cannot find java.exe...”,在網上看到很多人說要修改環境變量,但是偶的環境變量在安裝完jdk后就配置好了,沒有問題。
    于是又費了老半天的力氣,終于解決了,辦法如下:
    1,啟動jdk時 --jdkhome參數指出jdk路徑
    2,修改netbean目錄下的/etc目錄下的netbeans.conf中的jdkhome的值為當前jdk路徑

    使用上面方法中之一即可!

    posted @ 2007-03-11 16:54 Yemoo'S Java Blog 閱讀(4441) | 評論 (0)編輯 收藏

    /**
    ?*Description:greatest?common?divisor
    ?*Author:yemoo?2006.12.06
    ?
    */

    ?
    public ? class ?Pt32{
    ????
    // 思路:輾轉相除法
    ????? int ?divisor1( int ?m, int ?n){???? // 方法一:循環法
    ????????? int ?temp;
    ?????????
    if (m < n){???? // if?m<n,swap?m,n
    ?????????????temp = m;
    ?????????????m
    = n;
    ?????????????n
    = temp;
    ?????????}
    ?????????
    while (m % n != 0 ){
    ?????????????temp
    = n;
    ?????????????n
    = m % n;
    ?????????????m
    = temp;
    ?????????}
    ?????????
    return ?n;
    ?????}

    ?????
    int ?divisor2( int ?m, int ?n){???? // 方法二:遞歸法
    ????????? int ?temp;
    ?????????
    if (m < n){
    ?????????????temp
    = m;
    ?????????????m
    = n;
    ?????????????n
    = temp;
    ?????????}
    ?????????
    return ?divisor22(m,n);
    ?????}

    ????
    int ?divisor22( int ?m, int ?n){
    ????????
    if (m % n == 0 ){
    ????????????
    return ?n;
    ????????}
    else {
    ????????????
    return ?divisor22(n,m % n);
    ????????}
    ????}

    ?????
    public ? static ? void ?main(String?args[]){
    ?????????KeyboardInput?in
    = new ?KeyboardInput();
    ?????????Pt32?obj
    = new ?Pt32();
    ?????????System.out.println(
    " input?two?integer: " );
    ?????????
    int ?a = in.readInt();
    ?????????
    int ?b = in.readInt();
    ?????????System.out.println(a
    + " , " + b + " 's?greatest?common?divisor?is? " + obj.divisor2(a,b));
    ?????}

    ?}

    使用了輾轉相除法,分別使用循環和遞歸方法實現。

    吸取dreamstone大哥的程序寫法,發現判斷m、n大小的部分可以刪除,因為如果m<n求余部分會自動交換兩個變量。

    改進后程序代碼(精簡了好多哦):
    /**
    ?*Description:greatest?common?divisor
    ?*Author:yemoo?2006.12.07?
    */

    ?
    public?class?Pt32{
    ????
    //思路:輾轉相除法
    ?????int?divisor1(int?m,int?n){????//方法一:循環法
    ?????????int?temp;
    ?????????
    while(m%n!=0){
    ?????????????temp
    =n;
    ?????????????n
    =m%n;
    ?????????????m
    =temp;
    ?????????}
    ?????????
    return?n;
    ?????}

    ?????
    int?divisor2(int?m,int?n){????//方法二:遞歸法
    ?????????if(m%n==0){
    ????????????
    return?n;
    ????????}
    else{
    ????????????
    return?divisor2(n,m%n);
    ????????}
    ?????}

    ?????
    public?static?void?main(String?args[]){
    ?????????KeyboardInput?in
    =new?KeyboardInput();
    ?????????Pt32?obj
    =new?Pt32();
    ?????????System.out.println(
    "input?two?integer:");
    ?????????
    int?a=in.readInt();
    ?????????
    int?b=in.readInt();
    ?????????System.out.println(a
    +","+b+"'s?greatest?common?divisor?is?"+obj.divisor2(a,b));
    ?????}

    ?}

    posted @ 2006-12-07 01:02 Yemoo'S Java Blog 閱讀(7759) | 評論 (4)編輯 收藏

    主站蜘蛛池模板: 114级毛片免费观看| 国产91在线|亚洲| 特级毛片免费播放| 成人黄动漫画免费网站视频 | 午夜两性色视频免费网站| 亚洲人成伊人成综合网久久| 99热在线观看免费| 亚洲国产精品一区二区久| 国产高清免费视频| 中文字幕乱码亚洲精品一区| 丁香花在线观看免费观看 | 无码日韩人妻AV一区免费l | 国产精品成人无码免费| 日本亚洲高清乱码中文在线观看 | 亚洲国产精品自在在线观看| 国产一区二区三区免费| 无码专区—VA亚洲V天堂| 一级毛片**不卡免费播| 亚洲国产日韩女人aaaaaa毛片在线| 日本阿v免费费视频完整版| 亚洲砖码砖专无区2023| 国产人妖ts在线观看免费视频| 色网站在线免费观看| 亚洲精品中文字幕乱码三区| 国产情侣久久久久aⅴ免费| 亚洲自偷自偷精品| 丁香花免费高清视频完整版| 亚洲日韩精品无码专区加勒比☆| 四虎影视免费永久在线观看| a级毛片免费观看网站| 久久久无码精品亚洲日韩蜜臀浪潮| 4虎永免费最新永久免费地址| 国产精品亚洲专区无码唯爱网| 亚洲人成色777777在线观看 | 午夜a级成人免费毛片| 一级毛片在线免费视频| 亚洲日本在线观看| 免费无码又爽又刺激高潮| 精品国产污污免费网站入口| 亚洲国产成人va在线观看网址| 免费a级毛片无码av|