Configuration in struts 2.0 application:

When ever we are developing struts based application we have to do some configuration code changes. It includes the following:

1) web.xml- we have to specify the controler which will handle each request and determine the action to process the request.

Code Sample:



2) struts.xml and Most of the time we do not use, it is used to override the default properties.

In struts.xml we specify a lot of things like package, action, interceptors, results, global-exception esult, constant properties etc.


<!-- Package: We can have multiple packages with 
                             different namespace -->
   <package name="ankit" namespace="/" 
 <!-- Global Result-->
        <result name="exception">jsp/error.jsp</result>
<!-- Global Exception Mapping-->
        <exception-mapping exception="java.lang.Exception"
            result="exception" />
   <!-- Action -->
   <action name="examp" 
<!-- Interceptor -->         
		 <interceptor-ref name="params"/>
<!-- Result -->         
		 <result name="success">/Output.jsp</result>

We can have multiple file for configuration, so that we can easily maintain the code in seperate packages:

In main struts.xml we can have below entry:

<package name="def" namespace="/" extends="struts-default">  
<include file="a/struts-a.xml"></include>  
<include file="a/struts-b.xml"></include>  

Here struts-1.xml can have specification for a functionality and struts-b.xml will have specification for b functionality.