Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Need Help about Interceptors in Struts2

Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,

I am trying to create my application and need help of interceptors.

I have created Interceptor class named

package example;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

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

My struts.xml file is:

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

<package name="default" extends="struts-default">
<interceptor name="interceptorTest" class="example.InterceptorExample">

<action name="HelloWorld" class="example.HelloWorld">
<interceptor-ref name="interceptorTest"></interceptor-ref>



Now when i am trying to run my project on runs fine but I am not having any effects of interceptors.

What should i do to create workable from interceptors???

Is there any chances in struts.xml file or Interceptor class???

Please help me i m stuck
Ranch Hand
Posts: 35
Hibernate jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do you see your sop on console
Rushabh Vashi
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No i cant see my SOP...
but i found another way to get to know that interceptors are being called or not...
I just returned STATUS from intercept()...
and in struts.xml file i set <result=STATUS>somepage.jsp</result>

and its working....
He's dead Jim. Grab his tricorder. I'll get his wallet and this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic