Thursday, November 3, 2011

Configuring Struts.xml for Interceptors

Well learning curve is quite breath taking with java technologies. I got curious about the interceptors feature in Struts 2 and eventually I ended up trying to sample them out for my reference and understanding. I am not yet successful on it, but at least I have had some progress on the same.


The first wall I had to jump over was that whenever I added the interceptors tag in struts.xml, I was having a heap of issues and my page/ project wont load up on the browser.


I searched through out the innernet and all spoke about how to use them and what tags to add and I was so puzzeled that I followed them exactly as per my understanding and it wouldn’t work.


Gosh…. I found the culprit at last. It was the way in which these  tags needs to be ordered in the xml file.


The interceptors tag needs to be present on top of all other action tags. So much to my observation !!!!!  It was always there and yet it took me an hour to find it. L So much to experience with the RAD technology I am associated with, for the past 4 yrs… I never had to think about these silly stuffs


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
             
       <package name="default" extends="struts-default">
             
             
              <interceptors>
                     <interceptor name="logger" class="interceptor.MyLoggingInterceptor">
                     </interceptor>
                     <interceptor-stack name="loggingStack">
                           <interceptor-ref name="logger" />
                           <interceptor-ref name="defaultStack" />
                     </interceptor-stack>
                    
              </interceptors>           
             
              <!-- <constant name="struts.devMode" value="true" /> -->
             
              <action name….>
                     <result ….">/index.jsp</result>
              </action>

              <action name….>
                     <result ….>
                           ……
                     </result>
              </action>

              <action name="TestLogger" class="TestLoggerAction">
                     <interceptor-ref name="loggingStack" />
                     <result name="success">/InterceptorSuccess.jsp</result>
              </action>
             
       </package>   
</struts>
             
       Hope this xml interpretation gives you an idea of how to configure em…

Hope this helps some one J
      

No comments:

Post a Comment