j2ee(webwork、freemark、struts、jsf、spring、hibernate)

          不錯(cuò)學(xué)習(xí)j2ee的框架結(jié)構(gòu)。。。

          BlogJava 首頁(yè) 新隨筆 聯(lián)系 聚合 管理
            1 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

          Struts配置

           

          經(jīng)過幾天的努力和朋友的幫助,Struts終于搞清楚了

          環(huán)境 resin3.0.12+struts1.1

           

          1、  Jsp(視圖)

          2、  actionForm

          3、  action

          4、  模型

           

          視圖內(nèi)容:

          有標(biāo)簽和html語(yǔ)言組成。

          例如:

          <%@ include file="taglibs.jsp" %>

          <%-- 登錄驗(yàn)證視圖 2005/04/27 lanlanq --%>

           

          <html:errors/>

          <html:form action="/Logon.do">

          <center>

          <table border="0" width="100%">

           

                 <tr>

                        <th align="right">

                               <bean:message key="prompt.username"/>

                        </th>

                        <td align="left">

                               <html:text property="userName" size="15" maxlength="15" />

                        </td>

                 </tr>

           

                 <tr>

                        <th align="right">

                               <bean:message key="prompt.password"/>

                        </th>

                        <td align="left">

                               <html:password property="password" size="15" maxlength="15" />

                        </td>

                 </tr>

           

                 <tr>

                        <td align="right">

                               <html:submit property="submit" >

                                      <bean:message key="button.logon"/>

                               </html:submit>

                        </td>

                        <td align="left">

                               <html:reset>

                                      <bean:message key="button.reset"/>

                               </html:reset>

                        </td>

                 </tr>

                

          </table>

          </center>

          </html:form>

           

          首先配置一下resin3.0.12

          然后再工程目錄下的WEB-INF下創(chuàng)建lib文件夾,增加struts的支持類包

          然后創(chuàng)建TLD文件

          struts-bean.tld

          struts-html.tld

          struts-logic.tld

          這三個(gè)標(biāo)記庫(kù)文件

          以便在Jsp中進(jìn)行調(diào)用。

          然后創(chuàng)建struts-config.xml

          內(nèi)容如下:

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

           

          <!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-bean name="logonForm" type="member.forms.LogonForm"/>

              </form-beans>

           

            <!-- ========== Action Mapping Definitions ============================== -->

            <action-mappings>

              <!-- Say Hello! -->

              <action    path      = "/HelloWorld"

                         type      = "hello.HelloAction"

                         name      = "HelloForm"

                         scope     = "request"

                         validate  = "true"

                         input     = "/DateSouce/hello.jsp"

               >

                  <forward name="SayHello" path="/DateSouce/hello.jsp" />

              </action>

             

              <action    path      = "/Logon"

                         type      = "member.actions.LogonAction"

                         name      = "logonForm"

                         scope     = "request"

                         validate  = "true"

                         input     = "/DateSouce/error.jsp"

               >

                  <forward name="Success" path="/DateSouce/sucess.jsp" />      

              </action>

             

            </action-mappings>

           

           

            <!-- ========== Message Resources Definitions =========================== -->

           

            <message-resources parameter="application_ch_CN"/>

           

          </struts-config>

           

          這個(gè)文件是在運(yùn)行web服務(wù)器是首先要去找的配置文件

          其中的

            <form-beans>

                  <form-bean name="HelloForm" type="hello.HelloForm"/>

                  <form-bean name="logonForm" type="member.forms.LogonForm"/>

              </form-beans>

          表示jsp文件指定的actionForm文件

          其中的

          <action-mappings>

              <!-- Say Hello! -->

              <action    path      = "/HelloWorld"

                         type      = "hello.HelloAction"

                         name      = "HelloForm"

                         scope     = "request"

                         validate  = "true"

                         input     = "/DateSouce/hello.jsp"

               >

                  <forward name="SayHello" path="/DateSouce/hello.jsp" />

              </action>

             

              <action    path      = "/Logon"

                         type      = "member.actions.LogonAction"

                         name      = "logonForm"

                         scope     = "request"

                         validate  = "true"

                         input     = "/DateSouce/error.jsp"

               >

                  <forward name="Success" path="/DateSouce/sucess.jsp" />      

              </action>

          表示jsp中調(diào)用Html:form中的action=Logon.do文件的映射。

          其中的nameactionForm中的name保持一致。

          如果validate=”true”表示要執(zhí)行actionFormvalidate錯(cuò)誤處理。

           

          <message-resources parameter="application_ch_CN"/>

          表示國(guó)際標(biāo)準(zhǔn)化,再jsp頁(yè)面中的文字說(shuō)明都是通過application文件指定。

           

           

          創(chuàng)建actionForm時(shí)注意,在通過JBuilder生成actionForm時(shí)注意屬性名和jsp中的屬性名字保持一致,然后創(chuàng)建action,得execute方法,進(jìn)行邏輯處理。

           

          posted on 2006-03-10 11:55 luckystar 閱讀(274) 評(píng)論(0)  編輯  收藏 所屬分類: struts

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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 府谷县| 渝中区| 石门县| 丰城市| 鄂尔多斯市| 舒城县| 旅游| 富顺县| 隆尧县| 琼海市| 贡觉县| 磴口县| 元氏县| 福清市| 张家界市| 恩平市| 淅川县| 南康市| 将乐县| 普兰店市| 双城市| 保亭| 兴业县| 安吉县| 赣州市| 新晃| 湖南省| 库伦旗| 河源市| 康平县| 灵川县| 临西县| 三明市| 河池市| 山阴县| 松滋市| 永州市| 田阳县| 工布江达县| 大石桥市| 马鞍山市|