File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts2 Interceptor Error in struts.xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Interceptor Error in struts.xml file" Watch "Struts2 Interceptor Error in struts.xml file" New topic

Struts2 Interceptor Error in struts.xml file

Rushabh Vashi

Joined: Apr 27, 2011
Posts: 20
Hello everyone...

I am creating my application using Struts2 framework...

I have created Interceptor named InterceptorEx ....


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...");


"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


<interceptor name="interceptorTest" class="example.InterceptorEx">

<package name="default" extends="struts-default">
<action name="HelloWorld" class="example.HelloWorld">
<interceptor-ref name="interceptorTest"></interceptor-ref>
<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 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 name="Order" class="example.BeanExample">
<result name="SUCCESS">/example/BeanExample.jsp</result>
<result name="FAIL">/example/BeanExample.jsp</result>

<action name="modelAction" class="example.ModelAction" >
<result name="success">/example/modelView.jsp</result>

<action name="User" class="example.DispatchActionEx">
<result name="success">/example/DispatchAction.jsp</result>
<action name="*User" class="example.DispatchActionEx" method="{1}">
<result name="success">/example/DispatchAction.jsp</result>



now i am gettting errror in XML file.....
if i remove interceptor tags then it works fine.....
please help me friends....
Rupesh Mhatre
Ranch Hand

Joined: Apr 29, 2011
Posts: 35

place interceptor declaration in struts.xml within package declaration.
Rushabh Vashi

Joined: Apr 27, 2011
Posts: 20
yeah i do the same thing...and its working....thnx bro..
I agree. Here's the link:
subject: Struts2 Interceptor Error in struts.xml file
It's not a secret anymore!