Configuring the Web Application Descriptor

I l @ ve RuBoard

Now you need to edit the web.xml (see Listing 16.14) deployment file in the struts-bfg Web application directory to customize it for the application.

Listing 16.14 web.xml
 <?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"   "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd"> <web-app>   <servlet>     <servlet-name>log4j-init</servlet-name>     <servlet-class>com.bfg.services.Log4jInit</servlet-class>     <init-param>       <param-name>log4j-init-file</param-name>       <param-value>WEB-INF/log4j.properties</param-value>     </init-param>     <load-on-startup>1</load-on-startup>   </servlet>   <!-- 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>application</param-name>       <param-value>com.bfg.struts.ApplicationResources</param-value>     </init-param>     <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>     <init-param>       <param-name>validate</param-name>       <param-value>true</param-value>     </init-param>     <load-on-startup>2</load-on-startup>   </servlet>   <!-- Standard Action Servlet Mapping -->   <servlet-mapping>     <servlet-name>action</servlet-name>     <url-pattern>*.do</url-pattern>   </servlet-mapping>   <!-- The Usual Welcome File List -->   <welcome-file-list>     <welcome-file>index.jsp</welcome-file>   </welcome-file-list>   <!-- Struts Tag Library Descriptors -->   <taglib>     <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>     <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>   </taglib>   <taglib>     <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>     <taglib-location>/WEB-INF/struts-html.tld</taglib-location>   </taglib>   <taglib>     <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>     <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>   </taglib> </web-app> 

The top of the file is mostly the same as the one for the main BFG site ”setting up the Log4j logger.

The remainder of web.xml configures Struts. The only part that you care about is the ApplicationResources entry. As you should recall, it defines the property file used to store language-independent strings for all your prompts and Web content.

The servlet-mapping piece is the part that sets up the mapping that any file ending in .do will be handed off to the Struts ActionServlet for handling.

The taglib sections define the tag libraries that Struts needs to do its job and are available to developers under JSP.

To deploy the code, add some code to your build.xml (see Listing 16.15) for a new target called diststrut that deploys to the bfgstrut application. It should copy both the normal JSP files and your special Struts because the new JSP pages need some of the normal ones, such as autoLogin .

Listing 16.15 Additions to build.xml
 <property name="stappdir" value="${tomcatdir} /webapps/struts-bfg"/> . . .   <target name="diststrut" depends="compile">      <mkdir dir="${stappdir} /WEB-INF/lib"/>      <mkdir dir="${stappdir} /logs"/>      <jar jarfile="${stappdir} /WEB-INF/lib/${jarfile}">         <fileset dir="src" includes="**/*.class"/>         <fileset dir="props" includes="**/*.properties"/>       </jar>      <copy todir="${stappdir} /WEB-INF">         <fileset dir="." includes="struts/web.xml"/>         <fileset dir="." includes="TurbineResources.properties"/>         <fileset dir="props" includes="log4j.properties"/>      </copy>      <copy todir="${stappdir}">         <fileset dir="struts-jsp"/>      </copy>      <mkdir dir="${stappdir} /jsp"/>      <copy todir="${appdir} /jsp">         <fileset dir="jsp"/>      </copy>   </target> 

After doing an ant diststrut and restarting the server, go to http://localhost:8080/struts-bfg/myAccount.jsp and you'll get a display of your account, which is much the same as with the model 1 version that you wrote originally (see Figure 16.1).

Figure 16.1. The Struts version of MyAccount.

graphics/16fig01.jpg

When you edit a credit card, you can see the new multi-page credit card editing in operation. This code was fairly easy to write using Struts; it would have been much more involved if it had been done using model 1 (see Figures 16.2 and 16.3).

Figure 16.2. The first page of a multipage credit card form.

graphics/16fig02.jpg

Figure 16.3. The second page of a multipage credit card form.

graphics/16fig03.jpg

I l @ ve RuBoard


MySQL and JSP Web Applications. Data-Driven Programming Using Tomcat and MySQL
MySQL and JSP Web Applications: Data-Driven Programming Using Tomcat and MySQL
ISBN: 0672323095
EAN: 2147483647
Year: 2002
Pages: 203
Authors: James Turner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net