期待更好更穩(wěn)定的開源FrameWork的出現(xiàn),讓我們一起努力吧!  
          日歷
          <2007年6月>
          272829303112
          3456789
          10111213141516
          17181920212223
          24252627282930
          1234567
          統(tǒng)計(jì)
          • 隨筆 - 78
          • 文章 - 1
          • 評論 - 29
          • 引用 - 0

          導(dǎo)航

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案(42)

          文章檔案(37)

          相冊

          搜索

          •  

          積分與排名

          • 積分 - 45228
          • 排名 - 1064

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

           

           

                                   

          In this section I will describe you the Controller part of the Struts Framework. I will show you how to configure the struts-config.xml file to map the request to some destination servlet or jsp file.

          The class org.apache.struts.action.ActionServlet is the heart of the Struts Framework. It is the Controller part of the Struts Framework. ActionServlet is configured as Servlet in the web.xml file as shown in the following code snippets.

           

           

          <!-- Standard Action Servlet Configuration (with debugging) -->
          <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>
               <init-param>
                  <param-name>debug</param-name>
                  <param-value>2</param-value>
                  </init-param>
                  <init-param>
                  <param-name>detail</param-name>
                  <param-value>2</param-value>
               </init-param>
              <load-on-startup>2</load-on-startup>
          </servlet>

          This servlet is responsible for handing all the request for the Struts Framework, user can map the specific pattern of request to the ActionServlet. <servlet-mapping> tag in the web.xml file specifies the url pattern to be handled by the servlet. By default it is *.do, but it can be changed to anything. Following code form  the web.xml file shows the mapping.

          <!-- Standard Action Servlet Mapping -->
          <servlet-mapping>
              <servlet-name>action</servlet-name>
              <url-pattern>*.do</url-pattern>
          </servlet-mapping>

          The above mapping maps all the requests ending with .do to the ActionServlet. ActionServlet uses the configuration defined in struts-config.xml file to decide the destination of the request. Action Mapping Definitions (described below) is used to map any action. For this lesson we will create Welcome.jsp file and map the "Welcome.do" request to this page.

           

           

           

           

          Welcome.jsp

          <%@ taglib uri="/tags/struts-bean" prefix="bean" %>
          <%@ taglib uri="/tags/struts-html" prefix="html" %>
          <html:html locale="true">
          <head>
             <title><bean:message key="welcome.title"/></title>
             <html:base/>
          </head>
            <body bgcolor="white">
            <h3><bean:message key="welcome.heading"/></h3>
            <p><bean:message key="welcome.message"/></p>
          </body>
          </html:html>

          Forwarding the Welcome.do request to Welcome.jsp

          The "Action Mapping Definitions" is the most important part in the struts-config.xml. This section takes a form defined in the "Form Bean Definitions" section and maps it to an action class.

          Following code under the <action-mappings> tag is used to forward the request to the Welcome.jsp.

          <action  path="/Welcome"
                  forward="/pages/Welcome.jsp"
          />
            

          To call this Welcome.jsp file we will use the following code.

          <html:link page="/Welcome.do">First Request to the controller</html:link>

          Once the use clicks on on First Request to the controller link on the index page, request (for Welcome.do) is sent to the Controller and the controller forwards the request to Welcome.jsp. The content of Welcome.jsp is displayed to the user.



          posted on 2007-06-07 21:10 BlueSky_itwangxinli 閱讀(508) 評論(0)  編輯  收藏

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


          網(wǎng)站導(dǎo)航:
           
           
          Copyright © BlueSky_itwangxinli Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 弥渡县| 滕州市| 克山县| 岢岚县| 泌阳县| 上饶市| 高淳县| 清苑县| 镇宁| 广元市| 商水县| 宣恩县| 潞城市| 隆林| 迭部县| 灵山县| 赤城县| 常德市| 萨迦县| 南京市| 县级市| 涡阳县| 类乌齐县| 大同县| 宜丰县| 济阳县| 安宁市| 靖边县| 教育| 河东区| 汾阳市| 和龙市| 分宜县| 阿拉善左旗| 贵定县| 宣恩县| 肥城市| 元朗区| 开阳县| 衢州市| 察哈|