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

          不錯學習j2ee的框架結構。。。

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            1 Posts :: 1 Stories :: 0 Comments :: 0 Trackbacks

          Struts配置

           

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

          環境 resin3.0.12+struts1.1

           

          1、  Jsp(視圖)

          2、  actionForm

          3、  action

          4、  模型

           

          視圖內容:

          有標簽和html語言組成。

          例如:

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

          <%-- 登錄驗證視圖 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下創建lib文件夾,增加struts的支持類包

          然后創建TLD文件

          struts-bean.tld

          struts-html.tld

          struts-logic.tld

          這三個標記庫文件

          以便在Jsp中進行調用。

          然后創建struts-config.xml

          內容如下:

          <?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>

           

          這個文件是在運行web服務器是首先要去找的配置文件

          其中的

            <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中調用Html:form中的action=Logon.do文件的映射。

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

          如果validate=”true”表示要執行actionFormvalidate錯誤處理。

           

          <message-resources parameter="application_ch_CN"/>

          表示國際標準化,再jsp頁面中的文字說明都是通過application文件指定。

           

           

          創建actionForm時注意,在通過JBuilder生成actionForm時注意屬性名和jsp中的屬性名字保持一致,然后創建action,得execute方法,進行邏輯處理。

           

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

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 塘沽区| 全南县| 佛山市| 若羌县| 东辽县| 弥勒县| 常熟市| 绥江县| 朝阳市| 海林市| 菏泽市| 新田县| 新龙县| 哈巴河县| 新巴尔虎左旗| 尼勒克县| 门源| 双流县| 兴安县| 高州市| 霍邱县| 黑河市| 瓮安县| 衡山县| 盘山县| 武鸣县| 沭阳县| 潞西市| 克山县| 巴青县| 徐州市| 那坡县| 文安县| 新丰县| 尼勒克县| 海城市| 怀宁县| 上思县| 高州市| 射洪县| 四川省|