Struts Controller (I)

16 January 2008

Let us see 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 at 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.

<!-- 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 handling all the request for the Struts Framework, user can map the specific pattern of request to the ActionServlet. 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.

del.icio.us:Struts Controller (I)  digg:Struts Controller (I)  spurl:Struts Controller (I)  wists:Struts Controller (I)  simpy:Struts Controller (I)  newsvine:Struts Controller (I)  blinklist:Struts Controller (I)  furl:Struts Controller (I)  reddit:Struts Controller (I)  fark:Struts Controller (I)  blogmarks:Struts Controller (I)  Y!:Struts Controller (I)  smarking:Struts Controller (I)  magnolia:Struts Controller (I)  segnalo:Struts Controller (I)  gifttagging:Struts Controller (I)

Top Of Page | Trackback

If you found this page useful, consider linking to it. Simply copy and paste the code below into your web site.

It will look like this: Struts Controller (I)

Leave a Reply