Navigation Bar

Tuesday, September 15, 2009

Your first Struts application : The config files setup

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>

  <taglib>
    <taglib-uri>/tags/struts-html</taglib-uri>
    <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
  </taglib>
   
</web-app>

In the above we add a reference to the struts-html.tld file. 
Copy this struts-html.tld file from the lib directory of the extracted Struts archive to the 
<CALALINA_HOME>/webapps/strutsapp/WEB-INF folder.

struts-config.xml
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">


<struts-config>
	<form-beans>
		<form-bean  name="lookupForm"
               type="src.LookupForm"/>
	</form-beans>
	<action-mappings>
		<action path="/Lookup"
			type="src.LookupAction"
			name="lookupForm" >
		<forward name="success" path="/quote.jsp" />
		<forward name="failure" path="/index.jsp" />
		</action>	
	</action-mappings>
	<plug-in className="org.apache.struts.tiles.TilesPlugin" >
		<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
		<set-property property="moduleAware" value="true" />
		<set-property property="definitions-parser-validate" value="true" />
	</plug-in>
</struts-config>


A sample tiles-defs.xml

file. 
This file is to be copied to the CATALINA_HOME/webapps/getquote/WEB-INF folder
<?xml version="1.0" encoding="ISO-8859-1" ?>

 <!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 1.1//EN"
       "http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">

<!--
     This is a blank Tiles definition file with a commented example.
-->

<tiles-definitions>

    <!-- sample tiles definitions
    <definition name=".mainLayout" path="/common/layouts/classicLayout.jsp">
        <put name="title"  value="Sample Page Title" />
        <put name="header" value="/common/header.jsp" />
        <put name="menu"   value=".mainMenu" />
        <put name="footer" value="/common/footer.jsp" />
        <put name="body"   value=".portal.body" />
    </definition>

    <definition name=".mainMenu" path="/common/layouts/vboxLayout.jsp" >
        <putList name="list" >
            <add value=".menu.links" />
            <add value=".menu.taglib.references" />
            <add value=".menu.printer.friendly" />
            <add value=".menu.old.documents" />
      </putList>
    </definition>

    <definition name="aPage" extends=".mainLayout">
        <put name="title"  value="Another Title" />
        <put name="body"   value=".aPage.body" />
    </definition>

    end samples -->

    <definition name="${YOUR_DEFINITION_HERE}">
    </definition>

</tiles-definitions>

Whoever touches pitch gets dirty
  and whoever associates with a proud person becomes like him
Do not lift a weight too heavy for you
  or associate with one mightier or richer than you
How can the clay pot associate with the iron kettle?
  The pot will strike against it and be smashed. 
Sirach 13:1-2

No comments:

Post a Comment