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

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

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

    posts - 40,  comments - 7,  trackbacks - 0

    創建Web應用的配置文件

    對于Struts應用,它的配置文件web.xml應該對ActionServlet類進行配置,此外,還應該聲明Web應用所使用的Struts標簽庫,本例中聲明使用了三個標簽庫: Struts Bean、Struts HTML和Struts Logic標簽庫。例程1為web.xml的源代碼。

    例程1 web.xml

    <?xml version="1.0" encoding="UTF-8"?>

    <!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
    "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

    < web-app >

    < display-name >
    HelloApp Struts Application
    </display-name >

    <!-- Standard Action Servlet Configuration -->

    < servlet >

    < servlet-name > action </servlet-name >

    < servlet-class >
    org.apache.struts.action.ActionServlet
    < /servlet-class >

    < init-param >
    < param-name> config< /param-name >
    < param-value>
    /WEB-INF/struts-config.xml
    </param-value >
    </init-param >

    < load-on-startup>2</load-on-startup >

    </servlet>

    <!-- Standard Action Servlet Mapping -->

    < servlet-mapping>

    < servlet-name > action</servlet-name>

    < url-pattern>*.do</url-pattern>

    </servlet-mapping>

    <!-- The Usual Welcome File List -->

    < welcome-file-list>

    < welcome-file > hello.jsp</welcome-file>

    </welcome-file-list>

    <!-- Struts Tag Library Descriptors -->

    < taglib >

    < taglib-uri >
    /WEB-INF/struts-bean.tld
    </taglib-uri>

    < taglib-location>
    /WEB-INF/struts-bean.tld
    </taglib-location>

    </taglib>

    < taglib >

    < taglib-uri >
    /WEB-INF/struts-html.tld
    </taglib-uri >

    < taglib-location >
    /WEB-INF/struts-html.tld
    </taglib-location >

    </taglib >

    < taglib >

    < taglib-uri >
    /WEB-INF/struts-logic.tld
    </taglib-uri >

    < taglib-location >
    /WEB-INF/struts-logic.tld
    </taglib-location >

    </taglib >

    </web-app >

    創建Struts框架的配置文件

    正如前面提及的,Struts框架允許把應用劃分成多個組件,提高開發速度。而Struts框架的配置文件struts-config.xml可以把這些組件組裝起來,決定如何使用它們。例程2是helloapp應用的struts-config.xml文件的源代碼。

    例程2  struts-config.xml
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config
    PUBLIC"-//Apache Software Foundation
    //DTD Struts Configuration 1.1//EN"
    "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

    <!--This is the Struts configuration file
    for the "Hello!" sample application-->
    < struts-config>
    <!-- ===== Form Bean Definitions ====== -->
    < form-beans>
    < form-bean name="HelloForm" type="hello.HelloForm"/>
    </form-beans>
    <!-- ====== Action Mapping Definitions ====== -->
    < action-mappings>
    <!-- Say Hello! -->
    < action path="/HelloWorld"
    type="hello.HelloAction"
    name="HelloForm"
    scope="request"
    validate="true"
    input="/hello.jsp"
    >
    < forward name="SayHello" path="/hello.jsp" />
    </action >
    </action-mappings >
    <!-- ===== Message Resources Definitions ===== -->
    < message-resources parameter="hello.application"/>
    </struts-config >


    以上代碼對helloapp應用的HelloForm、HelloAction和消息資源文件進行了配置,首先通過元素配置了一個ActionForm Bean,名叫HelloForm,它對應的類為hello.HelloForm:



    接著通過元素配置了一個Action組件: 
    < action
    path = "/HelloWorld"
    type ="hello.HelloAction"
    name = "HelloForm"
    scope = "request"
    validate = "true"
    input = "/hello.jsp"
    >
    < forward name="SayHello" path="/hello.jsp" />
    </action >

    元素的path屬性指定請求訪問Action的路徑,type屬性指定Action的完整類名,name屬性指定需要傳遞給Action的ActionForm Bean,scope屬性指定ActionForm Bean的存放范圍,validate屬性指定是否執行表單驗證,input屬性指定當表單驗證失敗時的轉發路徑。元素還包含一個子元素,它定義了一個請求轉發路徑。

    本例中的 元素配置了HelloAction組件,對應的類為hello.HelloAction,請求訪問路徑為"HelloWorld",當Action類被調用時,Struts框架應該把已經包含表單數據的HelloForm Bean傳給它。HelloForm Bean存放在request范圍內,并且在調用Action類之前,應該進行表單驗證。如果表單驗證失敗,請求將被轉發到接收用戶輸入的網頁hello.jsp,讓用戶糾正錯誤。

    struts-config.xml文件最后通過元素定義了一個Resource Bundle:元素的parameter屬性指定Resource Bundle使用的消息資源文件。本例中parameter屬性為"hello.application",表明消息資源文件名為"application.properties",它的存放路徑為WEB-INF/classes/hello/application.properties。

    posted on 2006-08-17 19:43 Lansing 閱讀(335) 評論(0)  編輯  收藏 所屬分類: Java
    <2006年8月>
    303112345
    6789101112
    13141516171819
    20212223242526
    272829303112
    3456789

    歡迎探討,努力學習Java哈

    常用鏈接

    留言簿(3)

    隨筆分類

    隨筆檔案

    文章分類

    文章檔案

    Lansing's Download

    Lansing's Link

    我的博客

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 黄色片网站在线免费观看| 亚洲乱码中文论理电影| 精品亚洲福利一区二区| 免费观看的毛片大全| 亚洲黄网站wwwwww| 中文免费观看视频网站| 噜噜嘿在线视频免费观看| 亚洲免费在线观看视频| 国产精品免费精品自在线观看| 免费久久精品国产片香蕉| 亚洲午夜理论片在线观看| 国产精品成人啪精品视频免费| 人妻视频一区二区三区免费| 久久精品夜色噜噜亚洲A∨| 免费人成大片在线观看播放电影| 国产男女猛烈无遮档免费视频网站 | 久久久久久毛片免费看| 亚洲一区二区三区香蕉| 欧洲人免费视频网站在线| 亚洲国产精品第一区二区| 亚洲欧美成aⅴ人在线观看| 韩国免费三片在线视频| 亚洲成a人片77777老司机| 色欲国产麻豆一精品一AV一免费| 亚洲国产品综合人成综合网站| 一区二区无码免费视频网站| 亚洲小说区图片区另类春色| 韩国免费a级作爱片无码| 免费一级毛片在线观看| 人成免费在线视频| 在线观看无码的免费网站| 国产午夜亚洲精品不卡免下载| 亚洲av无码不卡私人影院| 久久久亚洲AV波多野结衣| 久久笫一福利免费导航| 精品无码专区亚洲| 久久精品国产亚洲网站| 国产va精品免费观看| 日韩毛片在线免费观看| 亚洲综合激情视频| 吃奶摸下高潮60分钟免费视频|