Hello everyone...
I am creating my application using Struts2 framework...
I have created Interceptor named
InterceptorEx ....
code..
package example;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class InterceptorEx implements Interceptor
{
private static final long serialVersionUID = 1L;
public
String intercept(ActionInvocation in) throws Exception
{
String className = in.getAction().getClass().getName();
long startTime = System.currentTimeMillis();
System.out.println("Before calling action: " + className);
String result = in.invoke();
long endTime = System.currentTimeMillis();
System.out.println("After calling action: " + className + " Time taken: " + (endTime - startTime) + " ms");
return result;
}
public void destroy()
{
System.out.println("Destroying Interceptor...");
}
public void init()
{
System.out.println("Initializing Interceptor...");
}
}
struts.xml
<!DOCTYPE
struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<interceptors>
<interceptor name="interceptorTest" class="example.InterceptorEx">
</interceptor>
</interceptors>
<package name="default" extends="struts-default">
<action name="HelloWorld" class="example.HelloWorld">
<interceptor-ref name="interceptorTest"></interceptor-ref>
<result>/example/HelloWorld.jsp</result>
</action>
<action name="welcome" class="example.Welcome">
<result name="REDIRECT" type="redirectAction">Register.action</result>
<result name="input">/example/welcome.jsp</result>
<result name="SUCCESS">/example/HelloWorld.jsp</result>
<result name="FAILIOUR">/example/welcome.jsp</result>
</action>
<action name="Register" class="example.RegisterAction">
<!--<result name="input">/example/Registration.jsp</result>-->
<result name="SUCCESS">/example/viewRegister.jsp</result>
<result name="POPULATE">/example/Registration.jsp</result>
<result name="ERROR">/example/welcome.jsp</result>
</action>
<action name="Order" class="example.BeanExample">
<result name="SUCCESS">/example/BeanExample.jsp</result>
<result name="FAIL">/example/BeanExample.jsp</result>
</action>
<action name="modelAction" class="example.ModelAction" >
<result name="success">/example/modelView.jsp</result>
</action>
<action name="User" class="example.DispatchActionEx">
<result name="success">/example/DispatchAction.jsp</result>
</action>
<action name="*User" class="example.DispatchActionEx" method="{1}">
<result name="success">/example/DispatchAction.jsp</result>
</action>
</package>
</struts>
now i am gettting errror in XML file.....
if i remove interceptor tags then it works fine.....
please help me friends....