Powered by Blogger.

struts-config.xml in Detail

>> Wednesday, June 29, 2011


The main tags in struts-config.xml are:


<data-sources/>
<form-beans/>
<global-forwards/>
<global-exceptions/>
<action-mappings/>
<controller/>
<message-resources/>
<plug-in/>

The basic example code of struts-config.xml as given below with all tags.


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

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

<struts-config>
 <!-- ========== DataSource properties ============ -->
 <data-sources>
  <data-source type="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
   <set-property property="driverClassName" value="com.mysql.jdbc.Driver" />
   <set-property property="url" value="jdbc:mysql://localhost:3306/strutsdatabase?autoReconnect=true" />
   <set-property property="username" value="root" />
   <set-property property="password" value="root" />
   <set-property property="maxActive" value="10" />
   <set-property property="maxWait" value="5000" />
   <set-property property="defaultAutoCommit" value="false" />
   <set-property property="defaultReadOnly" value="false" />
   <set-property property="validationQuery" value="SELECT COUNT(*) FROM test" />
  </data-source>
</data-sources>

  <!-- ========== Form Bean Definitions ============ -->
  <form-beans>
     <form-bean name="login" type="test.struts.LoginForm" />
  </form-beans>


  <!-- ========== Global Forward Definitions ========= -->
 <global-forwards>
    <forward   name="logoff" path="/logoff.do"/>
    <forward   name="logon"  path="/logon.jsp"/>
    <forward   name="success" path="/mainMenu.jsp"/>
 </global-forwards>
  <!-- ========== Global Exception Definitions ======== -->
 <global-exceptions>
     <exception
   key="error.io.key"
   type="java.io.IOException"
   path="/error.jsp" />
 </global-exceptions>

  <!-- ========== Action Mapping Definitions ======== -->
 <action    path="/editSubscription"
    type="org.apache.struts.webapp.example.EditSubscriptionAction"
    attribute="subscriptionForm"
    scope="request"
    validate="false">
  <forward name="failure" path="/mainMenu.jsp"/>
  <forward name="success" path="/subscription.jsp"/>
 </action>

 <!-- ========== Controller ============ -->
  <controller
       processorClass="org.apache.struts.action.RequestProcessor"
          contentType="text/html"/>;

  <!-- ========== Message Resources ============ -->
  <message-resources parameter="MyWebAppResources" null="false" />

 <!-- ========== PlugIns ============ -->
  <plug-in className="org.apache.struts.tiles.TilesPlugin">
    <set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml"/>
  </plug-in>


</struts-config>

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2014. All rights reserved.