Useful links

regular expressions tutorial
http://www.developer.com/lang/article.php/3330231
http://gnosis.cx/publish/programming/regular_expressions.html
http://www.cc.gatech.edu/classes/RWL/Projects/citation/Docs/Design/regex.intro.1.doc.html
This is a good website for struts related doubts
http://www.mail-archive.com/struts-user@jakarta.apache.org/
I found this link on web.xml that contained a lot of information. http://edocs.bea.com/wls/docs61/webapp/webappdeployment.html#1012209
For graphs use cewolf
http://sourceforge.net/projects/cewolf
(Download the webapp too so that you can get the look and feel)and for charts use
http://www.jfree.org/jfreechart/
After starting POD, select the word (in any other application) forwhich you want to know the meaning and press Control+C. The word andits meaning will be displayed on the top of the POD window.
http://www.download.com/Oxford-Dictionary-of-English-Second-Edition-/3000-2279_4-10238905.html
You can use this for comparing files.
http://www.tucows.com/preview/214649.html
Gel: Native java ide esp useful to work with jsps
http://www.tucows.com/preview/246670.html

Practical example using FOP for PDF generation (updated)

The FOP API has changed so I had to update the code in this post. The code is compatible with the latest FOP jars available at the time of writing.

Here is a practical example using FOP for PDF generation.Click on the image above to enlarge it and view the output of the program.

Code for ExampleFO2PDF follows:


package com.mattiz.fop;

//Java
import java.io.File;
import java.io.OutputStream;

//JAXP
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Source;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXResult;

//FOP
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;

/**
 * This class demonstrates the conversion of an XML file to PDF using JAXP
 * (XSLT) and FOP (XSL-FO).
 */
public class ExampleFO2PDF {

	/**
	 * Main method.
	 *
	 * @param args
	 *            command-line arguments
	 */
	public static void main(String[] args) {
		try {
			System.out.println("FOP ExampleXML2PDF\n");
			System.out.println("Preparing...");

			// Setup directories
			File baseDir = new File(".");
			File outDir = new File(baseDir, "out");
			outDir.mkdirs();

			// Setup input and output files
			File xmlfile = new File(baseDir, "xml/xml/test.xml");
			File xsltfile = new File(baseDir, "xml/xslt/test.xsl");
			File pdffile = new File(outDir, "ResultXML2PDF.pdf");

			System.out.println("Input: XML (" + xmlfile + ")");
			System.out.println("Stylesheet: " + xsltfile);
			System.out.println("Output: PDF (" + pdffile + ")");
			System.out.println();
			System.out.println("Transforming...");

			// configure fopFactory as desired
			FopFactory fopFactory = FopFactory.newInstance();

			FOUserAgent foUserAgent = fopFactory.newFOUserAgent();
			// configure foUserAgent as desired

			// Setup output
			OutputStream out = new java.io.FileOutputStream(pdffile);
			out = new java.io.BufferedOutputStream(out);

			try {
				// Construct fop with desired output format
				Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF,
						foUserAgent, out);

				// Setup XSLT
				TransformerFactory factory = TransformerFactory.newInstance();
				Transformer transformer = factory
						.newTransformer(new StreamSource(xsltfile));

				// Set the value of a <param> in the stylesheet
				transformer.setParameter("versionParam", "2.0");

				// Setup input for XSLT transformation
				Source src = new StreamSource(xmlfile);

				// Resulting SAX events (the generated FO) must be piped through
				// to FOP
				Result res = new SAXResult(fop.getDefaultHandler());

				// Start XSLT transformation and FOP processing
				transformer.transform(src, res);
			} finally {
				out.close();
			}

			System.out.println("Success!");
		} catch (Exception e) {
			System.out.print("ERROR!!");
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}
}

Create a web project and put all the jars in the FOP download on the classpath.

Put the following xml and xsl files in the appropriate folder:

test.xsl


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:template match="/">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
			<fo:layout-master-set>
				<fo:simple-page-master master-name="simple"
					page-height="8.5in" page-width="11in" margin-top=".5in"
					margin-bottom=".5in" margin-left=".5in" margin-right=".5in">
					<fo:region-body margin-top="2cm" margin-bottom="2cm" />
					<fo:region-before extent="2cm" overflow="hidden" />
					<fo:region-after extent="1cm" overflow="hidden" />
				</fo:simple-page-master>
			</fo:layout-master-set>
			<fo:page-sequence master-reference="simple"
				initial-page-number="1">
				<fo:static-content flow-name="xsl-region-before">
					<fo:block font-size="13.0pt" font-family="serif"
						padding-after="2.0pt" space-before="4.0pt" text-align="center"
						border-bottom-style="solid" border-bottom-width="1.0pt">
						<xsl:text>Worth of a Man</xsl:text>
					</fo:block>
				</fo:static-content>
				<fo:static-content flow-name="xsl-region-after">
					<fo:block font-size="12.0pt" font-family="sans-serif"
						padding-after="2.0pt" space-before="2.0pt" text-align="center"
						border-top-style="solid" border-bottom-width="1.0pt">
						<xsl:text>Page</xsl:text>
						<fo:page-number />
					</fo:block>
				</fo:static-content>
				<fo:flow flow-name="xsl-region-body">
					<xsl:apply-templates select="data" />
				</fo:flow>
			</fo:page-sequence>
		</fo:root>
	</xsl:template>
	<xsl:template match="data">
		<fo:block text-align="center">
			<fo:table table-layout="fixed" width="100%">
				<fo:table-column column-width="3in" />
				<fo:table-column column-width="2in" />
				<fo:table-column column-width="1in" />
				<fo:table-body>
					<fo:table-row keep-together.within-page="always">
						<fo:table-cell>
							<fo:block font-size="10pt" font-family="sans-serif"
								background-color="grey" color="white" text-align="left"
								padding-top="3pt">
								Field
</fo:block>
						</fo:table-cell>
						<fo:table-cell>
							<fo:block font-size="10pt" font-family="sans-serif"
								background-color="grey" color="white" text-align="left"
								padding-top="3pt">
								Data Entered
</fo:block>
						</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
			</fo:table>
			<fo:table table-layout="fixed" width="100%">
				<fo:table-column column-width="3in" />
				<fo:table-column column-width="2in" />
				<fo:table-column column-width="1in" />
				<fo:table-body>
					<fo:table-row keep-together.within-page="always">
						<fo:table-cell>
							<xsl:apply-templates select="field" />
						</fo:table-cell>
						<fo:table-cell>
							<xsl:apply-templates select="data-entered" />
						</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
			</fo:table>
			<fo:table table-layout="fixed" width="100%">
				<fo:table-column column-width="4.2in" />
				<fo:table-column column-width="2in" />
				<fo:table-column column-width="2in" />
				<fo:table-body>
					<fo:table-row keep-together.within-page="always">
						<fo:table-cell padding="2pt" border="1pt solid black">
							<fo:block font-size="10pt" font-family="sans-serif"
								space-after.optimum="1pt" background-color="red" color="white"
								text-align="left" padding-top="3pt">
								Measure
</fo:block>
						</fo:table-cell>
						<fo:table-cell padding="2pt" border="1pt solid black">
							<fo:block font-size="10pt" font-family="sans-serif"
								space-after.optimum="1pt" background-color="red" color="white"
								text-align="left" padding-top="3pt">
								Category
</fo:block>
						</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
			</fo:table>
			<fo:table table-layout="fixed" width="100%">
				<fo:table-column column-width="4.2in" />
				<fo:table-column column-width="2in" />
				<fo:table-column column-width="2in" />
				<fo:table-body>
					<fo:table-row keep-together.within-page="always">
						<fo:table-cell padding="2pt" border="1pt solid black">
							<xsl:apply-templates select="measure" />
						</fo:table-cell>
						<fo:table-cell padding="2pt" border="1pt solid black">
							<xsl:apply-templates select="category" />
						</fo:table-cell>
					</fo:table-row>
				</fo:table-body>
			</fo:table>
		</fo:block>
	</xsl:template>
	<xsl:template match="field">
		<fo:block font-size="9pt" font-family="sans-serif"
			space-after.optimum="1pt" text-align="justify">
			<xsl:value-of select="." />
		</fo:block>
	</xsl:template>
	<xsl:template match="data-entered">
		<fo:block font-size="9pt" font-family="sans-serif"
			space-after.optimum="1pt" text-align="justify">
			<xsl:value-of select="." />
		</fo:block>
	</xsl:template>
	<xsl:template match="measure">
		<fo:block font-size="9pt" font-family="sans-serif"
			space-after.optimum="1pt" text-align="justify">
			<xsl:value-of select="." />
		</fo:block>
	</xsl:template>
	<xsl:template match="category">
		<fo:block font-size="9pt" font-family="sans-serif"
			space-after.optimum="1pt" text-align="justify">
			<xsl:value-of select="." />
		</fo:block>
	</xsl:template>
</xsl:stylesheet>

test.xml


<?xml version="1.0" encoding="UTF-8"?>
<data>
	<field>First Name</field>
	<data-entered>Jock</data-entered>
	<field>Second Name</field>
	<data-entered>Hoffman</data-entered>
	<field>Middle Name</field>
	<data-entered>Luther</data-entered>
	<field>Address1</field>
	<data-entered>Rose Villa</data-entered>
	<field>Address2</field>
	<data-entered>Picadilly</data-entered>
	<field>City</field>
	<data-entered>London</data-entered>
	<field>Date Of Joining</field>
	<data-entered>6/10/2005</data-entered>
	<field>Date of Birth</field>
	<data-entered>01-01-1971</data-entered>
	<field>Sex</field>
	<data-entered>Male</data-entered>
	<field>Marital Status</field>
	<data-entered>Unmarried</data-entered>
	<field>Name of Spouse</field>
	<data-entered>Not applicable</data-entered>
	<field>Credit card Number</field>
	<data-entered>01-03222-32</data-entered>
	<field>Land Phone</field>
	<data-entered>1234567890</data-entered>
	<field>Mobile Phone</field>
	<data-entered>Not Applicable</data-entered>
	<field>Education</field>
	<data-entered>Post graduate</data-entered>
	<field>Passport Number</field>
	<data-entered>1212</data-entered>
	<field>Date of Issue</field>
	<data-entered>08-08-2004</data-entered>
	<field>Date of Expiry</field>
	<data-entered>08-09-2008</data-entered>
	<measure>
		Overall bright person with a sunny disposition and few
		prejudices
</measure>
	<category>
		An asset to our company and we are sure he will take our company
		to new heights and a prosperous future
</category>
</data>

Run the ExampleFO2PDF as a standalone application.

Struts: Beans inside Beans

Bean inside Bean inside Bean

public class UniversityDetails implements Serializable {
	private ArrayList outerArr;// contains SchoolDetails objects
	private int deanName;
	private int location;
	// setters and getters for instance variables


public class SchoolDetails {
	private ArrayList innerArr;// contains StudentDetails objects
	private String schoolName;
	private int totalCount;
	// setters and getters for instance variables


public class StudentDetails {
	private String age;
	private String sex;
	private int height;
	// setters and getters for instance variables
<table>
    <logic:iterate id="SchoolDetails" name="UniversityDetails"
        property="outerArr">
        <tr>
            <td><font size=2><nested:write name="SchoolDetails"
                        property="schoolName" />
            </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
        </tr>
        <nested:iterate id="StudentDetails" name="SchoolDetails"
            property="innerArr">
            <tr>
                <td><font size=2> </font>
                </td>
                <td><font size=2><nested:write name="StudentDetails"
                            property="age" />
                </font>
                </td>
                <td><font size=2><nested:write name="StudentDetails"
                            property="sex" />
                </font>
                </td>
                <td><font size=2><nested:write name="StudentDetails"
                            property="height" />
                </font>
                </td>
            </tr>
        </nested:iterate>
        <tr>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2> </font>
            </td>
            <td><font size=2><nested:write name="SchoolDetails"
                        property="totalCount" />
            </font>
            </td>
        </tr>
    </logic:iterate>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td><font size=2><bean:write name="UniversityDetails"
                    property="deanName" />
        </font>
        </td>
    </tr>
    <tr>
        <td></td>
        <td></td>
        <td></td>
        <td><font size=2><bean:write name="UniversityDetails"
                    property="location" />
        </font>
        </td>
    </tr>
</table>

Bean inside Bean

public class SchoolDetails implements Serializable {
	private String schoolName;
	private String totalCount;
	private ArrayList classes = new ArrayList();// contains ClassDetails objects
	// setters and getters for the above instance variables
}

public class ClassDetails {
	private int srNumber;
	private String standard;
	private String classteacher;
	private String noOfStudents;
	// setters and getters for the above instance variables
}

<table>
    <logic:iterate id="ClassDetails" name="SchoolDetails"
        property="classes">
        <tr>
            <td><font size=2><nested:write name="ClassDetails"
                        property="srNumber" />
            </font>
            </td>
            <td><font size=2><nested:write name="ClassDetails"
                        property="standard" />
            </font>
            </td>
            <td><font size=2><nested:write name="ClassDetails"
                        property="classteacher" />
            </font>
            </td>
            <td><font size=2><nested:write name="ClassDetails"
                        property="noOfStudents" />
            </font>
            </td>
        </tr>
    </logic:iterate>
    <tr>
        <td></td>
        <td></td>
        <td><font size=2><bean:write name="SchoolDetails"
                    property="schoolName" />
        </font>
        </td>
        <td><font size=2><bean:write name="SchoolDetails"
                    property="totalCount" />
        </font>
        </td>
    </tr>
</table>

What data can the Request and Session objects hold?

In the case of request dispatcher – forward or include methods, the request object is transferred as well, along with all parameters that it holds.
sendRedirect, fresh doPost/ doGet result in fresh request objects, hence data contained in the request object is not universally available in the session, and in fact, is temporary to the extent of transmitting from client-to-servlet and between servlet-chains.
Hence session-tracking comes into the picture. Session-tracking internally uses cookies to implement its functioning and is alive until it times-out or is invalidated, so the data stored in a session is in fact serialized and written on the client side in the form of cookies (in small files)…
Hence session objects can hold data across multiple screens of an application that will not be lost unless the session is explicitly invalidated by the code or the browser is closed.
Another point to be considered is that the request object can only hold small string values (parameters) that are generated by the client and cannot be manipulated between servlet chains.
In contrast, sessions can be loaded with entire objects that can be modified (and accessed) by any participating servlet/ jsp of the application.

HttpTunneling – Proof of Concept

Here is the code for the HttpTunnelServer in project tunnel in package tunnel residing on the web server. (Tomcat 4.1\webapps\tunnel\WEB-INF\classes\tunnel\HttpTunnelServer.class) Note that HttpTunnelServer is simply a java servlet.


package tunnel;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HttpTunnelServer extends HttpServlet {

	public void doPost(javax.servlet.http.HttpServletRequest request,
			javax.servlet.http.HttpServletResponse response)
			throws javax.servlet.ServletException, java.io.IOException {

		// get the data the client sent

		ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(
				request.getInputStream()));
		String messageFromRJ = null;
		try {
			messageFromRJ = (String) in.readObject();
		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
		System.out.println("Got from the client [" + messageFromRJ + "]");
		in.close();
		// send reply to client

		ObjectOutputStream out = new ObjectOutputStream(
				new BufferedOutputStream(response.getOutputStream()));
		out.writeObject("Hi RJ, this is the server");

		out.flush();
		out.close();

	}

	public void doGet(javax.servlet.http.HttpServletRequest request,
			javax.servlet.http.HttpServletResponse response)
			throws javax.servlet.ServletException, java.io.IOException {

		throw new ServletException("I expect only doPosts!!");

	}

}

web.xml (Tomcat 4.1\webapps\tunnel\WEB-INF\web.xml) looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>fopwork</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>default.html</welcome-file>
        <welcome-file>default.htm</welcome-file>
        <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>HttpTunnelServer</servlet-name>
        <servlet-class>tunnel.HttpTunnelServer</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>HttpTunnelServer</servlet-name>
        <url-pattern>/HttpTunnelServer</url-pattern>
    </servlet-mapping>
</web-app>

The Client, which calls the HttpTunnelServer, looks as below. Start web server and run the Client class as a standalone application from its location anywhere on the machine
Viz. java Client


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Client {

	public static void main(String[] args) {

		try {
			URL servletToCall = new URL(
					"http://localhost:8080/tunnel/HttpTunnelServer");
			URLConnection servletConn = servletToCall.openConnection();
			servletConn.setUseCaches(false);

			// send data to server

			servletConn.setDoOutput(true);
			servletConn.setRequestProperty("Content-Type",
					"application/octet-stream");
			ObjectOutputStream out = new ObjectOutputStream(
					new BufferedOutputStream(servletConn.getOutputStream()));
			String sendMeToServer = "Hey Server, this is R.J. - how's it going?";
			out.writeObject(sendMeToServer);
			out.flush();

			// get reply from server

			// use same connection we got earlier, no need to open another one

			ObjectInputStream in = new ObjectInputStream(
					new BufferedInputStream(servletConn.getInputStream()));
			String replyFromServer = (String) in.readObject();
			System.out.println("Got reply from server [" + replyFromServer
					+ "]");

		} catch (Exception e) {
			e.printStackTrace(System.out);
		}
	}
}

Output on the client side

D:\m2m\tunnel_ex>java Client
Got reply from server [Hi RJ, this is the server]

Corresponding output on the web server

INFO: Jk running ID=0 time=0/31 config=C:\:Program Files\Apache Group\Tomcat 4.1\conf\jk2.properties
Got from the client [Hey Server, this is R.J. – how’s it going?]

Note: Do not call the HttpTunnelServer directly on a browser: it will simply throw an exception.

Using Tiles in Struts- A Proof of Concept

This example builds on the StrutsEntityEJB example and some of the components have been reused. refer post – “EJB with STRUTS”
The following files are unchanged:
application.xml, ApplicationResources.properties, ejb-jar.xml, jboss.xml, jbosscmp-jdbc.xml, mysql-ds.xml, build.xml, build.properties remain unchanged. There is no change in authorsAction or authorsForm classes.
The entity bean classes remain unchanged and are reused.

The structure of work folder is as follows:

mysql-ds.xml
jbosscmp-jdbc.xml
ejb-jar.xml
jboss.xml
application.xml
ApplicationResources.properties
build.xml
build.properties
build.bat
struts-config.xml
web.xml
<build>
<pages>
      |layout.jsp
      |authorsAddTiles.jsp
      |authorsAdd.jsp
      |authorsSearchTiles.jsp
      |authorsSearch.jsp
      |sucessTiles.jsp
      |success.jsp
      |header.jsp
      |menu.jsp
      |copyright.jsp
<src>
      |<shoppingcart>
           |AuthorsBean.java
           |Authors.java
           |AuthorsHome.java
           |AuthorsKey.java
           |authorsForm.java
           |authorsAction.java

web.xml is modified to include struts-tiles.tld
web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
	<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>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<servlet-mapping>
		<servlet-name>action</servlet-name>
		<url-pattern>*.matty</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>authors.jsp</welcome-file>
	</welcome-file-list>
	<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>
	<taglib>
		<taglib-uri> /web-inf/struts-tiles.tld”</taglib-uri>
		<taglib-location> WEB-INF/struts- tiles.tld</taglib-location>
	</taglib>
</web-app>

struts-config.xml has been modfied to call the appropriate jsp in the action mapping.

struts-config.xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
	<form-beans type="org.apache.struts.action.ActionFormBean">
		<form-bean name="authorsForm" type="shoppingcart.authorsForm" />
	</form-beans>
	<action-mappings type="org.apache.struts.action.ActionMapping">
		<action path="/testout" type="shoppingcart.authorsAction" name="authorsForm"
			scope="request" validate="false">
			<b>
				<forward name="successful" path="/successTiles.jsp" />
			</b>
		</action>
	</action-mappings>
	<message-resources parameter="ApplicationResources" />
</struts-config>

None of the jsps have been reused.
The following jsps have replaced authors.jsp and success.jsp

layout.jsp


<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<html:html>
<head>
<title>Tiles Struts EJB Application</title>
<html:base />
</head>
<body topmargin="0" leftmargin="0" bgcolor="#FFFFFF">
	<table width="100%" border="0">
		<tr>
			<td colspan=2><!—-Header page information--> <tiles:insert
					attribute="header" /></td>
		</tr>
		<tr>
			<td width="20%"><tiles:insert attribute="navibar" /></td>
			<td width="80%"><!—-Main body information--> <tiles:insert
					attribute="body-content" /></td>
		</tr>
		<tr>
			<td colspan=2><!—-copyright information --> <tiles:insert
					attribute="copyright" /></td>
		</tr>
</body>
</html:html>

header.jsp

<center><h1>Search or Find an Entity </h1></center>

menu.jsp


<a href = "/authorsAddTiles.jsp">Add</a><br/>
<a href = "/authorsSearchTiles.jsp">Search</a>

copyright.jsp

<center><h4>(c)This is copyright stuff that you can use</h4></center>

authorsAddTiles.jsp

<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<tiles:insert page="layout.jsp" flush="true">
	<tiles:put name="header" value="header.jsp" />
	<tiles:put name="navibar" value="menu.jsp" />
	<tiles:put name="body-content" value="authorsAdd.jsp" />
	<tiles:put name="copyright" value="copyright.jsp" />
</tiles:insert>

authorsAdd.jsp

<html>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<head>
</head>
<body>
	<html:form action="/testout.matty">
		<p>
			<html:errors />
			<br />
			<bean:message key="isbnCode.label" />
			<html:text property="isbnCode" size='10' />
			<br />
			<bean:message key="author.label" />
			<html:text property="author" size='10' />
			</br>
			<html:submit value='Add' property="add" />
	</html:form>
</body>
</html>

authorsSearchTiles.jsp

<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<tiles:insert page="layout.jsp" flush="true">
	<tiles:put name="header" value="header.jsp" />
	<tiles:put name="navibar" value="menu.jsp" />
	<tiles:put name="body-content" value="authorsSearch.jsp" />
	<tiles:put name="copyright" value="copyright.jsp" />
</tiles:insert>

authorsSearch.jsp

<html>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<head>
</head>
<body>
	<html:form action="/testout.matty">
		<p>
			<html:errors />
			<br />
			<bean:message key="isbnCode.label" />
			<html:text property="isbnCode" size='10' />
			<br /> <br />
			<html:submit value='Find' property="find" />
	</html:form>
</body>
</html>

successTiles.jsp


<%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%>
<tiles:insert page="layout.jsp" flush="true">
	<tiles:put name="header" value="header.jsp" />
	<tiles:put name="navibar" value="menu.jsp" />
	<tiles:put name="body-content" value="success.jsp" />
	<tiles:put name="copyright" value="copyright.jsp" />
</tiles:insert>

success.jsp

<html>
<head>
</head>
<body>
	<%
		if (request.getAttribute("author") != null) {
	%>
	<h3>
		ISBN CODE
		<%=request.getAttribute("isbnCode")%></h3>
	<%
		}
	%>
	<%
		if (request.getAttribute("isbnCode") != null) {
	%>
	<h3>
		AUTHOR
		<%=request.getAttribute("author")%></h3>
	<%
		}
	%>
</body>
</html>

The structure of the ear file is as follows:

authors.ear
    |<meta-INF>
         |application.xml
    |authors.jar
         |<meta-INF>
             |ejb-jar.xml
             |jboss.xml
             |jbosscmp-jdbc.xml
         |<shoppingcart>
             |AuthorsBean.class
             |Authors.class
             |AuthorsHome.class
             |AuthorsKey.class
    |authors.war
         |add.jpg
         |find.jpg
         |layout.jsp
         |authorsAddTiles.jsp
         |authorsAdd.jsp
         |authorsSearchTiles.jsp
         |authorsSearch.jsp
         |sucessTiles.jsp
         |success.jsp
         |header.jsp
         |menu.jsp
         |copyright.jsp
         |<meta-INF>
         |<web-INF>
             |struts-config.xml
             |web.xml
             |struts-bean.tld
             |struts-html.tld
             |struts-logic.tld
             |struts-nested.tld
             |struts-logic.tld
             |struts-tiles.tld
             |<classes>
                 |ApplicationResources.properties
                 |<shoppingcart>
                          |Authors.class
                          |AuthorsKey.class
                          |AuthorsHome.class
                          |authorsForm.class
                          |authorsAction.class
             |<lib>
                 |jnp-client.java
                 |jboss-client.jar
                 |struts.jar

You can start the application by either typing
http://localhost:8080/authorsSearchTiles.jsp
Or
http://localhost:8080/authorsAddTiles.jsp
You can toggle between the search and add pages while the header, navigation bar and footer remain unchanged.