[ Team LiB ] Previous Section Next Section

Configuring Struts

To tie into the power of Struts with your WebLogic Server 8.1 application, the web.xml file must be modified with Struts framework information. The web.xml file is located in the WEB-INF directory and contains information about the Web application. To modify this file, use a simple text editor or an XML editor. The first thing that must be done is to register the action servlet within web.xml. Looking at the sample code shown in Listing 19.1, <servlet> .. </servlet> tags encapsulate this entire procedure. Line 2 registers the action name to the Struts action class in Line 3. The first parameter value supplied, application (in lines 47),must refer to a properties file that keeps user-defined text references used with Struts tag libraries within JSPs. The second parameter, config, in lines 811, refers to the locations of a Struts-specific configuration file that maps how and in what order JSP and servlet pages will be called (this file will be handled in depth later in the chapter). Lines 1417 map the action servlets to the .do extension, which is the default mapping for Struts. This mapping allows Struts actions to be mapped like .jsp pages. However, these actions could call many JSP pages based on the struts-config.xml file. Finally, lines 1844 register the Struts-specific tag libraries to WebLogic.

Listing 19.1 Web.xml
<!-- Action Servlet Configuration -->
 1  <servlet>
 2    <servlet-name>action</servlet-name>
 3    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
 4    <init-param>
 5      <param-name>application</param-name>
 6      <param-value>myApp.properties.ApplicationResources</param-value>
 7    </init-param>
 8    <init-param>
 9      <param-name>config</param-name>
10      <param-value>/WEB-INF/struts-config.xml</param-value>
11    </init-param>
12    </servlet>
13 <!-- Action Servlet Mapping -->
14  <servlet-mapping>
15    <servlet-name>action</servlet-name>
16    <url-pattern>*.do</url-pattern>
17  </servlet-mapping>
18  <!-- Application Tag Library Descriptor -->
19  <taglib>
20    <taglib-uri>/WEB-INF/lib/app.tld</taglib-uri>
21    <taglib-location>/WEB-INF/lib/app.tld</taglib-location>
22  </taglib>
23  <!-- Struts Tag Library Descriptor -->
24  <taglib>
25    <taglib-uri>/WEB-INF/lib/struts.tld</taglib-uri>
26    <taglib-location>/WEB-INF/lib/struts.tld</taglib-location>
27  </taglib>
28  <!-- Struts Tag Library Descriptors -->
29  <taglib>
30    <taglib-uri>/WEB-INF/lib/struts-bean.tld</taglib-uri>
31    <taglib-location>/WEB-INF/lib/struts-bean.tld</taglib-location>
32  </taglib>
33  <taglib>
34    <taglib-uri>/WEB-INF/lib/struts-form.tld</taglib-uri>
35    <taglib-location>/WEB-INF/lib/struts-form.tld</taglib-location>
36  </taglib>
37  <taglib>
38    <taglib-uri>/WEB-INF/lib/struts-logic.tld</taglib-uri>
39    <taglib-location>/WEB-INF/lib/struts-logic.tld</taglib-location>
40  </taglib>
41  <taglib>
42    <taglib-uri>/WEB-INF/lib/struts-template.tld</taglib-uri>
43    <taglib-location>/WEB-INF/lib/struts-template.tld</taglib-location>
44  </taglib>
    [ Team LiB ] Previous Section Next Section